迄今爲止,我已經從SO上獲得了很多幫助,但是我已經步入了一個我陷入困境的步伐。我可以得到這個工作的單數組合框,但它不是jiving當我在DataGridTemplate中這樣做。我希望FXCItem屬性可以獲取從組合框中選擇的任何值,但總是返回null。此外,我的ConfigItems屬性中的'SET'方法根本沒有被拋出。我在這裏錯過了什麼?先謝謝你!WPF Datagrid DataTemplate ComboBo不捕獲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>
如果您已經定義FXCItem? – RAJ
@RAJ,你釘了它!非常感謝!我有綁定屬性錯誤!我一直在看這個太久了,我無法從樹上看到森林!萬分感謝! – user576838