Following the answers in these 2:
Using WPF DataGridComboBoxColumn with MVVM - Binding to Property in ViewModel
Binding a WPF DataGridComboBoxColumn with MVVM
1) I can't get the values in the ObservableCollections to be set when a selection in the combobox is made.
The comboboxes are being populated with the List from the ViewModel but values are not being set.
Code:
<DataGrid ItemsSource="{Binding SidValues1through5, Mode=TwoWay}"
AutoGenerateColumns="False"
Grid.Row="1"
Margin="5"
VerticalAlignment="Top"
HorizontalAlignment="Center">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="1"
Width="100"
SelectedValueBinding="{Binding Value1}"
SelectedValuePath="Value1">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.AvailableSids}" />
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.AvailableSids}" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
ViewModel interface (I've debugged and I am connected to the ViewModel, other controls on the view are bound correctly:
ETA: BindableCollection inherits from ObservableCollection it's a Caliburn.Micro type.
public interface ICustomSIDViewModel : IScreen
{
BindableCollection<SidValues> SidValues1through5 { get; set; }
BindableCollection<SidValues> SidValues6through10 { get; set; }
IList<string> AvailableSids { get; }
}
public class SidValues
{
public string Value1 { get; set; }
public string Value2 { get; set; }
public string Value3 { get; set; }
public string Value4 { get; set; }
public string Value5 { get; set; }
}
2) Once I resolve this is there a cleaner way to have all the columns inherit this one set of DataGridComboBoxColumn.ElementStyle and DataGridComboBoxColumn.EditingElementStyle?
Reason I ask is there are 10 columns all will have the same combobox list.