views:

27

answers:

1

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 ?

+1  A: 

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

MrDosu