Other ItemsSource in WPF
I have a DataGrid dg;
and I would like to display a DataGridComboBoxColumn
with data populated from some list (using binding). Using XAML I have dg.ItemsSource
properly set but I do not know, how to set the column's ItemsSource
:
<D开发者_开发技巧ataGridComboBoxColumn ItemsSource={?????????} />
James
You can use the datacontext to get the property you are tying to bind to your DataGridComboBoxColumn.Check the below post
Binding a WPF DataGridComboBoxColumn with MVVM
<DataGridComboBoxColumn ItemsSource="{Binding AvailableOptions}" />
Here, AvailableOptions
is a property of a data item bound to the grid row. This property should contain a list of options available in the combo box.
Update:
If the collection of options to select from is fixed you could use ObjectDataProvider
defined in resources. See http://blogs.ugidotnet.org/ccavalli/archive/2006/02/09/34592.aspx for example.
In your case it could be something like this:
<ObjectDataProvider x:Key="Options" ObjectType="{x:Type my:MyOptions}" />
-
<DataGridComboBoxColumn ItemsSource="{Binding Source={StaticResource Options}}" />
精彩评论