I wanted to use "Xceed DataGrid for WPF" community edition to show items in WPF application that are already coming correct for a Propertygrid.
The textbox (first name) is working fine, but combobox is not working. Problem is combobox is not populating anything and it is not setting the gender correctly. My simple code is given below.
XAML:
<Window.Resources>
<xcdg:DataGridCollectionViewSource x:Key="mySource" Source="{Binding Path=SelectedEntity}" />
</Window.Resources>
<Grid>
<xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource mySource}}" AutoCreateColumns="True">
<xcdg:DataGridControl.Columns>
<xcdg:Column FieldName="FirstName" Title="First Name" />
<xcdg:Column FieldName="Gender" Title="Gender" >
<xcdg:Column.CellContentTemplate>
<DataTemplate x:Name="clmGenderTmp">
<ComboBox SelectedValuePath="GenderID"
DisplayMemberPath="Name"
ItemsSource="{Binding Path=SelectedEntity.Gender, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
SelectedValue="{xcdg:CellEditorBinding}"/>
</DataTemplate>
</xcdg:Column.CellContentTemplate>
</xcdg:Column>
</xcdg:DataGridControl.Columns>
</xcdg:DataGridControl>
</Grid>
Xaml.cs is:
InitializeComponent();
this.DataContext = new MainWindowViewModel();
Data class is:
using System.ComponentModel;
using Xceed.Wpf.DataGrid;
public enum Genders { Male, Female }
public class Person
{
public Person(string firstName, Genders gender)
{
FirstName = firstName;
Gender = gender;
}
[DisplayName("Given name")]
public string FirstName { get; set; }
[Browsable(true)]
public Genders Gender { get; set; }
}
View Model is:
public class MainWindowViewModel
{
public List<object> SelectedEntity { get; set; }
public MainWindowViewModel()
{
SelectedEntity = new List<object>();
this.SelectedEntity.Add(new Person("Mathew", Genders.Male));
this.SelectedEntity.Add(new Person("Mark", Genders.Female));
}
}