开发者

How to get Current object from TreeView

开发者 https://www.devze.com 2023-01-04 21:46 出处:网络
I have WPF treeView which has ControlTemplate which show every node of tr开发者_如何学GoeeView consisting of two elements : Image + Textbox. When I change TextBox treeView element not select. But I wa

I have WPF treeView which has ControlTemplate which show every node of tr开发者_如何学GoeeView consisting of two elements : Image + Textbox. When I change TextBox treeView element not select. But I want to get Selected class in TextChanged event of TextBox. How can I get class to which current textBox Bound in code behind.


Try this:

Bind textbox's IsFocused property to treeviewitems's IsSelected property

<TextBox IsFocused = {Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Mode="OneWayToSource"} />

Else Add a trigger to the textbox such that whenever the IsFocused property is set to true, the corresponding treeviewitem's IsSelected property is also set true.

0

精彩评论

暂无评论...
验证码 换一张
取 消