我有一个专栏:
<DataGridComboBoxColumn Header="Master" SelectedValueBinding="{Binding MasterId}" SelectedValuePath="Id" DisplayMemberPath="Name" ItemsSource="{Binding Data.Masters, Source={StaticResource proxy}}" />ViewModel上的属性是:
public ObservableCollection<ReaderViewModel> Masters { get; set; }DataGrid DataSource有一个自我关系主服务器,我在任何Insert/ update /Delete上更新集合,但是ComboBox保留初始值,而不更新自己。
我做错了什么?
对于属性的改变,我使用的是Fody副词。如果你需要更多的代码来理解这个问题,我准备分享更多。
编辑1:
BindingProxy类:
public class BindingProxy : Freezable
{
#region Overrides of Freezable
protected override Freezable CreateInstanceCore()
{
return new BindingProxy();
}
#endregion
public object Data
{
get
{
return GetValue(DataProperty);
}
set
{
SetValue(DataProperty, value);
}
}
public static readonly DependencyProperty DataProperty = DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null));
}这个类可以在Google上找到,我就是在那里找到的。
编辑2:
<DataGrid.Resources>
<classes:BindingProxy x:Key="proxy" Data="{Binding}" />
</DataGrid.Resources>如何使用BindingProxy。
发布于 2016-07-18 08:02:12
试试这个:
<DataGridComboBoxColumn Header="Master" SelectedValueBinding="{Binding MasterId}" SelectedValuePath="Id" DisplayMemberPath="Name" ItemsSource="{Binding Data.Masters, Source={StaticResource proxy, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}}" />更新:
private ObservableCollection<ReaderViewModel> masters;
public ObservableCollection<ReaderViewModel> Masters
{
get
{
return masters;
}
set
{
masters = value;
OnPropertyChanged("Masters");
}
}
protected void OnPropertyChanged(String propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this,
new PropertyChangedEventArgs(propertyName));
}XAML:
<DataGridComboBoxColumn Header="Master" Binding="{Binding Name}" SelectedValueBinding="{Binding MasterId}" SelectedValuePath="Id" ItemsSource="{Binding Masters, UpdateSourceTrigger=PropertyChanged}">
<DataGridComboBoxColumn.Resources>
<local:BindingProxy x:Key="proxy" Data="{Binding}"/>
</DataGridComboBoxColumn.Resources>
</DataGridComboBoxColumn>https://stackoverflow.com/questions/38431209
复制相似问题