I have a list of user objects: let's say Fruits with two string properties Name and Color. They are on the list.
private readonly List<Fruit> fruitList = new List<Fruit>();
Then I load the fruit objects into the list.
I am trying to associate this list with WPF Datagrid:
FROM#:
dgFruit.ItemsSource = "{Binding}";
XAML:
<toolkit:DataGrid Name="dgFruit"
ItemsSource="{Binding Path=fruitList}" >
<toolkit:DataGrid.Columns>
<toolkit:DataGridComboBoxColumn
Header="Name"
SelectedValueBinding="{Binding Path=Name}"
TextBinding="{Binding Path=Name}" Width="5*" />
<toolkit:DataGridComboBoxColumn
Header="Color"
SelectedValueBinding="{Binding Path=Color}"
TextBinding="{Binding Path=Color}" Width="5*" />
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
The reason they are in combobox is because I want the user to be able to change relationships. This is not a real example, but you understood this idea. Say, for the sake of example, the fruits were not ripe, so they change the color of the banana to green :)
I will not be able to get these elements in a datagrid ... and down the track, I want to click an element in a datagridcell to go to combobox and show all possible types of fruit names and colors (this way they can change relationships)
Here is the error I get:
System.Windows.Data Error: 39 : BindingExpression path error: 'Color' property not found on 'object' ''Char' (HashCode=6750311)'. BindingExpression:Path=Color; DataItem='Char' (HashCode=6750311); target element is 'TextBlockComboBox' (Name=''); target property is 'Text' (type 'String')
- ? , xaml, - , .
, ObservableCollection, , ?
, knwo,
: :
XAML:
<toolkit:DataGrid Name="dgFruit"
ItemsSource="{Binding}"
AutoGenerateColumns="False">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn
Header="Name"
Width="5*"/>
<toolkit:DataGridComboBoxColumn
Header="Color"
Width="5*"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
#:
DataContext = fruitList;
, DataContext, . ItemSource, , , .
, , . autogeneratecolumns false, xaml, , , !