开发者

How do I get current ListViewItem with a control in ItemTemplate, WPF

开发者 https://www.devze.com 2023-01-18 04:34 出处:网络
I have the开发者_运维技巧 following code: <ListView.ItemTemplate> <DataTemplate> <StackPanelName=\"stackPanel\" Orientation=\"Horizontal\">

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

精彩评论

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