Datagrid combobox binding problem

Dec 25, 2010 at 5:16 AM


I am stuck at this problem now, I have Two collections in my VM, in my view bound my datagrid's itemssource to one collection, and Datagridcombobox itemssource to the other one. to get the VM as datacontext, i usually create a Framework element in usercontrol.resources with a key (we call it bridge). and then the datagridcombo itemssource will be bound to this bridge's datacontext. it works normally (when i was using caliburn). but is not working with Cinch. how do i make it work ?

Dec 26, 2010 at 7:41 AM

Juts give the View iteself and x:Name something like x:Name="theView" in the XAML. And then use ElementName binding on each, so something like



ItemSource="{Binding Element=theView, Path=DataContext.ViewModelCollection1}"


ItemSource="{Binding Element=theView, Path=DataContext.ViewModelCollection2}"

Jan 3, 2011 at 1:22 PM
Edited Jan 3, 2011 at 1:31 PM

For the DataGridComboBoxColumn you have to create a StaticRecource of the ItemsSource like:

<CollectionViewSource Source="{Binding Element=theView, Path=DataContext.ViewModelCollection1}" x:Key="ViewModelCollection1" />

and bind it to the DataGridComboBoxColumn with

ItemsSource="{Binding Source={StaticResource ViewModelCollection1}}"

Thats because the DataGridColumns are not a part of the visual tree.

And if you want to bind on a collection of a item of the DataGrid you have to set the ItemsSource over the two styles:

    <Style TargetType="ComboBox">
        <Setter Property="ItemsSource" Value="{Binding Path=ModelCollection1}" />
    <Style TargetType="ComboBox">
        <Setter Property="ItemsSource" Value="{Binding Path=ModelCollection1}" />
Jan 4, 2011 at 8:12 AM

Helmut seems to have the answer here too Wilzad