0
考慮下面的XAML代碼:走控件樹在WPF
<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>
當文本框失去焦點,我想在第一列標籤的價值。我如何通過代碼來做到這一點?文本框的Parent屬性爲null。
嘗試:從TextBox_LostFocus_1處理程序設置屬性[((MyRowVM)textBox.DataContext).HasFocus =假。在MyRowVM.HasFocus的setter中,this.Name應該給你正確的Label。 – Gishu