开发者

Other ItemsSource in WPF

开发者 https://www.devze.com 2023-03-08 01:40 出处:网络
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 s

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}}" />
0

精彩评论

暂无评论...
验证码 换一张
取 消