Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider lazy evaluation in conditional expressions #63

Open
kunom opened this issue Jun 17, 2020 · 3 comments
Open

Consider lazy evaluation in conditional expressions #63

kunom opened this issue Jun 17, 2020 · 3 comments

Comments

@kunom
Copy link

kunom commented Jun 17, 2020

Consider the following binding expression: {calc:Binding 'MessagesFiltered.Count > 0 ? MessagesFiltered[0] : null'}

When MessagesFiltered is empty, I see in the binding log the message below, which is exactly what the above binding expression tried to avoid.

System.Windows.Data Warning: 17 : Cannot get 'Item[]' value (type 'LogMessageWithSource') from 'MessagesFiltered' (type 'ObservableCollection`1'). BindingExpression:Path=MessagesFiltered[0]; DataItem='LogMessagesViewModel' (HashCode=50930930); target element is 'Button' (Name=''); target property is 'CommandParameter' (type 'Object') ArgumentOutOfRangeException:'System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index'

Is there the possibility to introduce lazy evaluation in such circumstances, or at least improve the error handling?

(Note: I also tried using a converter calling Enumerable.FirstOrDefault(), but then you lose the change tracking.)

@keytrap-x86
Copy link

What is the MessagesFiltered ? A list or array ?

@kunom
Copy link
Author

kunom commented Dec 14, 2020

@varKeytrap MessagesFiltered is of type ObservableCollection<SomeInternalT>.

@metal450
Copy link

I'm having the same issue. Can't seem to figure out how to look at a property in an array, without it throwing up errors. {c:Binding 'Items.Count > 0 and !Items[0].SomeBool'} behaves the same: it's functional, but it prints an ArgumentOutOfRangeException.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants