I have custom objects which implement INotifyProperyChanged and now I'm wondering if it is possible to implement soft delete which would play nicely with binding? Each object would have a IsDeleted property and if this property is set to true than it would not be displayed in GUI. I was thinking about making a custom markup extension which would decorate Binding class but it hadn't worked out as expected. Now I'm considering using MultiBinding with IsDe开发者_如何学Goleted as one of bound properties so that converter would be able to figure out which object is deleted. But this solution sounds quite complicated and boring.
Does anybody have an idea how to implement soft deletes for binding?
You can bind the Property Visibility of the UIElement to the property IsDeleted of your object, to hide or show the elements.
As an example i use a TextBlock. In XAML you can write
<TextBlock Text="IsDeleted" Visibility={Binding IsDeleted}/>
NOTE: In the example above, the TextBlock is visible, when IsDeleted is true. I would define a positive property, such as Exists on the object. So you do not have to negate the boolean or to build your own converter.
WPF has a buildin converter that converts boolean to an enum value of Visibility.
Another way to implement soft deletes is by maintaining and exposing a collection containing only those items that haven't been deleted in your view model in addition to the collection of all items. This has the (to my mind) very great merit that it's not something your view needs to think about at all.
精彩评论