开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜