ViewModel&模型(这是在按钮'click'事件中填充的):
class ConfigViewModel : ViewModelEntity
{
public Settings Settings { get; set; }
public List<String> FileTypes { get; set; }
public List<String> Delimiters { get; set; }
public List<string> FXCFields { get; set; }
protected ObservableCollection<ConfigItem> _ConfigItems = new ObservableCollection<ConfigItem>();
public ObservableCollection<ConfigItem> ConfigItems
{
get { return _ConfigItems; }
set
{
if (_ConfigItems != value)
{
_ConfigItems = value;
NotifyPropertyChanged("ConfigItems");
}
}
}}
class ConfigItem
{
public string InputField { get; set; }
public string FXCField { get; set; }
public ConfigItem(string InputFieldName)
{
this.InputField = InputFieldName;
}
}
XAML:
<DataGrid x:Name="dgConfig" HorizontalAlignment="Left" Margin="40.66,98,0,0" VerticalAlignment="Top" Height="300.486" Width="323" AutoGenerateColumns="False" ItemsSource="{Binding ConfigItems}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding InputField}" Header="Input Fields"/>
<DataGridTemplateColumn Header="FXC Fields">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=DataContext.FXCFields, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
SelectedItem="{Binding Path=FXCItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=DataContext.FXCFields, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
SelectedItem="{Binding Path=FXCItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
答案 0 :(得分:0)
尝试
NotifyPropertyChanged("FXCFields");