我有一個綁定到不同屬性的TextBoxes列表。TextBox - 綁定屬性名稱
<TextBox Text="{Binding Name, Mode=TwoWay,ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True}" VerticalAlignment="Center" Margin="5" Width="300" Grid.Column="1" Grid.Row="1" LostFocus="TextBox_Validate"/>
我想自己寫一個處理程序,如
private void TextBox_Validate(object sender, RoutedEventArgs e)
{
var textBox = (sender as TextBox);
if(textBox!=null)
{
var propertyName = X; // Get propertyName textBox.Text is bound to.
CurrentDataContext.ValidateFields("Name"); // Name in this specific textBox
}
}
是否有可能獲得屬性的名稱,這樣我就不用寫做同樣的事情很多不同的方法呢?
太棒了!正是我需要的! – 2013-02-27 07:56:50