views:

46

answers:

2

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 would be 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 IsDeleted 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?

+2  A: 

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.

Jehof
I did something similar to what you suggested. I have two properties in my base type, ie. IsDeleted and Visiblity, which returns Visiblity.Collapsed if IsDeleted == true.
aks
+1  A: 

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.

Robert Rossney
Although this solution is perfect if one is using MVVM or something similar, which i'm for this project, I'd have problem rewriting an important part of application at this point.
aks