How do I bind the ListViews visibility to a calculation? I want the Listviews to be visible ONLY if there are more than one record in the DataContexts Collection (IEnumerable)
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can create a property CollectionAny on a ViewModel, which will call IEnumerable.Any() method. You can return Visibility directly from your ViewModel, but it is not recommended by MVVM pattern. So you are able to use converter, such as BooleanToVisibilityConverter. If you can wrap your collection to a ICollecitionView interface, you can use its IsEmpty property. If it is your choice – you do not need to raise PropertyChanged event.
Here example of binding boolean property to Visibility: