How do I get current ListViewItem with a control in ItemTemplate, WPF
I have the开发者_运维技巧 following code:
<ListView.ItemTemplate>
<DataTemplate>
<StackPanelName="stackPanel" Orientation="Horizontal">
<TextBoxName="textBoxOrg"
Background="Transparent" BorderThickness="0" TextWrapping="Wrap" Text="{BindingOrgText}"
IsReadOnly="True"/>
<TextBoxName="textBoxNew"
Background="Transparent" BorderThickness="0" TextWrapping="Wrap" Text="{BindingNewText}"
AcceptsReturn="True"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
Now i want to get the parent control(ListViewItem) focused by using textBoxNew_GotFocus,but when I use textboxNew.Parent, it returns an error what "Can not convert DependencyObject to Control". what should i do ?
You can walk through the visual tree by using VisualTreeHelper.GetParent. The visual/logical tree concepts are quite central to the whole WPF experience. One good read is: http://www.codeproject.com/KB/WPF/WpfElementTrees.aspx
精彩评论