0
votes

I want to bind SelectedItem of the combo box with a value converter to DataGridTextColumn after it. I am using MVVM pattern.

<Datagrid>
    <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 the ViewModel bound to SelectedItem of the combo box.

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

1

1 Answers

0
votes

So what's stopping you from using IValueConverter. Declare under Resource section and use it like this:

<DataGrid.Resources>
   <namespace:MyConverter x:Key="MyConverter"/>
</DataGrid.Resources>
.....
<DataGridTextColumn Header="Right"
                    Binding="{Binding SelectedColumn, Mode=OneWay, 
                                      UpdateSourceTrigger=PropertyChanged,
                                      Converter={StaticResource MyConverter}}"/>