鉴于以下XAML:
<ListView Name="UnitProperties" Grid.Column="2">
<ListView.View>
<GridView>
<GridViewColumn Header="Property">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=Name}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Value">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Value}" LostFocus="TextBox_LostFocus_1" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
当TextBox失去焦点时,我想获得第一列中标签的值。我如何通过代码执行此操作?文本框的Parent属性为null。
答案 0 :(得分:0)
在TextBox_LostFocus处理程序中,您可以像这样获取Name属性的值 -
var dataContext = (sender as TextBox).DataContext;
string labelContent = dataContext.Name;