有一个DataTemplate是绑定到一个DataView上的,代码如下:
        <DataTemplate x:Key="FriendTemplate">
            <Grid  >
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <StackPanel  Grid.Row="0" Orientation="Horizontal">
                <Label Content="{Binding Path=fusername}" Name="fname" Grid.Row="0"/>
                <Label Content="{Binding Path=status}" Name="status" Grid.Row="0"  />
                </StackPanel>
                <Label Content="{Binding Path=re}" Name="re" Grid.Row="1"/>
                <Grid.ContextMenu>
                    <ContextMenu Name="rightMenu" StaysOpen="True">
                        <MenuItem Header="好友资料" Click="MenuItem_Click_ContactInfo"  Name="contactInfo" />
                    </ContextMenu>
                </Grid.ContextMenu>
            </Grid>
        </DataTemplate>
请问在这个contactInfo点击后如何获取那个label的name属性值?

解决方案 »

  1.   

    解决了,用ContextMenuService.GetPlacementTarget(LogicalTreeHelper.GetParent(sender as MenuItem))
      

  2.   

    解决了就好,有些问题自己先百度、google后,如果实在解决不了再来提问。
      

  3.   

    帮人找下,就搜索到你的这个问题。你的解决方案也许是解决了问题但是!在WPF里,除非你是设计用户控件层,WPF的设计不建议使用逻辑树视图。当你需要使用逻辑树视图的时候,只能说明逻辑结构不好。而这个问题显然不是逻辑结构不好(WPF自带的,怎么会存在这个问题)。