0
votes

I want to bind SelectedItem of Combobox with a value converter to "DataGridTextColumn" after it. I am using MVVM pattern.

<Datagrid>
    <DataGrid.Columns>
       <DataGridTemplateColumn Header="Left">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <ComboBox Name="Leftcombo" ItemsSource="{Binding Path=DataContext.Column, RelativeSource={RelativeSource AncestorType=Window}}" 
                              SelectedItem="{Binding SelectedColumn, UpdateSourceTrigger=PropertyChanged}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
        <DataGridTextColumn Header="Right" Binding="{Binding SelectedColumn, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
    </DataGrid.Columns>
</DataGrid>

Please note: SelectedColumn is a property in viewmodel bound to Selected item of combobox.

Binding works the way it is in xaml above but, I want to use a value converter on the "DataGridTextColumn Header="Right"" Column.

1
What exactly are you having trouble with? It's not clear from your question.Iain
You haven't define CellEditingTemplate for the template column. Using an editor in cell template can lead to all kind of issues. Is there any reason for you to not choose the suggested way?AjS
@Iain I am trying to use value converter on DataGridTextColumn.user2330678

1 Answers

0
votes

I think you need to try Mode = TwoWay.

<Datagrid>
    <DataGrid.Columns>
       <DataGridTemplateColumn Header="Left">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <ComboBox Name="Leftcombo" ItemsSource="{Binding Path=DataContext.Column, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=Window}}" 
                              SelectedItem="{Binding SelectedColumn, UpdateSourceTrigger=PropertyChanged}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
        <DataGridTextColumn Header="Right" Binding="{Binding SelectedColumn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
    </DataGrid.Columns>
</DataGrid>