C# 如何在WPF中编辑数据网格中的值?
我的数据网格在itemsSource中有一个组列表:C# 如何在WPF中编辑数据网格中的值?,c#,wpf,C#,Wpf,我的数据网格在itemsSource中有一个组列表: public class Group : INotifyPropertyChanged { public Group() { } public Group(int groupID, string groupName) { this.GroupID = groupID; this.GroupName = groupName; } private int _groupID
public class Group : INotifyPropertyChanged
{
public Group() { }
public Group(int groupID, string groupName)
{
this.GroupID = groupID;
this.GroupName = groupName;
}
private int _groupID;
public int GroupID
{
get { return _groupID; }
set
{
_groupID = value;
OnPropertyChanged("GroupID");
}
}
private string _groupName;
public string GroupName
{
get { return _groupName; }
set
{
_groupName = value;
OnPropertyChanged("GroupName");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string property)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
}
但我意识到,当我编辑一个单元格时,我需要按Enter键从Group类中激发PropertyChanged。因此,如果我只编辑单元格值,除非我按Enter键,否则不要触发事件
不按Enter键编辑单元格值时是否可能触发事件?您需要将默认双向绑定更改为UpdateSourceTrigger=“PropertyChanged” MSDN中的示例:
<TextBox Name="itemNameTextBox"
Text="{Binding Path=ItemName, UpdateSourceTrigger=PropertyChanged}" />
例如:
UpdateSourceTrigger绑定属性页:您需要将默认双向绑定更改为UpdateSourceTrigger=“PropertyChanged” MSDN中的示例:
<TextBox Name="itemNameTextBox"
Text="{Binding Path=ItemName, UpdateSourceTrigger=PropertyChanged}" />
例如:
UpdateSourceTrigger绑定属性页:您需要在xaml中使用UpdateSourceTrigger 有三种不同的类型:
您需要在xaml中使用UpdateSourcetrigger 有三种不同的类型: