Question

I try to set an element in a treeView to "IsEnabled" = false but I want that the user can select the item. Is this possible?

Background: User can undelete Items (IsEnabled = false) but he also can undelete Items but therefore he has to select the item but with "IsEnabled" = false it doesn't work.

Workaround: Set the color of the "deleted" item to another. Problem: Child items doesn't change there colors and the user can open the "deleted" root node

Example:

Bracket Document Sheet

All enabled

now i delete the Document

Bracket (del)Document Sheet

With "IsEnabled" false for the (del)Document the user cant ever select the document to undelete it. With Color change for the (del)Document, the Sheet doesn't change the color.

I use the MVVM pattern for my project.

No correct solution

OTHER TIPS

Given your general question I think the simplest solution is to do it like you said and add a recursive ChangeColor() for TreeView items.

This method should iterate through its children and call ChangeColor() on its children too.

I try to set an element in a treeView to "IsEnabled" = false but I want that the user can select the item. Is this possible?

No, this is not possible. From the UIElement.IsEnabled Documentation:

Elements that are not enabled do not participate in hit testing or focus and therefore will not be sources of input events.

This means a disabled element cannot get the mouse down/click events and there for can not be selected.

I think you are on the correct way with your workaround. You can represent the 'deleted' state in your viewmodel and update the color of your elements depending on this state.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top