0

I'm trying do bind a DataGrid with the ViewModel. DataGrid visibility, ItemSource and column bindings work, but if I try to bind values as RowDetailsVisibilityMode, or the column header's text, the binding doesn't work. I tried to watch if the variables are binded correctly via debug, and if I point to te XAML while debugging and the informations are correctly binded.

What should I do to bind this DataGrid?

A:

<DataGrid Grid.Row="1" Grid.Column="0" ItemsSource="{Binding GridItemSource}" SelectedItem="{Binding SelectedGridItem}" RowDetailsVisibilityMode="{Binding RowDetailsVisibility}">

    <DataGrid.Columns>
        <DataGridTextColumn Header="HeaderA" Binding="{Binding ParameterA}" Width="30*"/>
        <DataGridTextColumn Header="HeaderB" Binding="{Binding ParameterB}" Width="30*"/>
        <DataGridTextColumn Header="HeaderC" Binding="{Binding ParameterC}" Width="30*"/>
    </DataGrid.Columns>

</DataGrid>

B:

<DataGrid.Columns>
    <DataGridTextColumn Header="{Binding ColumnNameA}" Binding="{Binding ParameterA}" Width="30*"/>
    <DataGridTextColumn Header="{Binding ColumnNameB}" Binding="{Binding ParameterB}" Width="30*"/>
    <DataGridTextColumn Header="{Binding ColumnNameC}" Binding="{Binding ParameterC}" Width="30*"/>
</DataGrid.Columns>

I'd like to go from situation A to situation B

Edit:

I tried this approach

<DataGridTextColumn.HeaderTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding Path=HeaderName, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>
    </DataTemplate>
</DataGridTextColumn.HeaderTemplate>

And the string doesn't show up

The situation now is that if I write

<TextBlock Text="Header name"/>

I see the text, if I bind it i see a blank space.

Since I also have to bind the visibility of the row details I tried to bind the Property RowDetailsVisibilityMode with a bool (using a conveter) and this binding too doesn't work.

  • Did you see [this](https://stackoverflow.com/questions/22073740/binding-visibility-for-datagridcolumn-in-wpf)? – mm8 May 27 '19 at 13:19
  • Yes, doesn't work. – Marco Perrone May 27 '19 at 13:30
  • The problem is that I have to switch between different visualizations. One with the details and another with no details and while switching I have to also change the text of the column header. I'm trying with this proxy method, but it doesn't seem to work.. – Marco Perrone May 27 '19 at 13:43
  • Yes, and even this didn't work.. the only bindings working are the ones related to the object in the ItemSource.. I'm actually evaluating what's better between this mess and switching between two DataGrids.. Binding the Datagrid is far more complicated than i thought. – Marco Perrone May 27 '19 at 13:46
  • Don't say "doesn't work" without showing us what you have actually tried. It makes no sense. – mm8 May 27 '19 at 13:47
  • Could you see the edit? – Marco Perrone May 27 '19 at 14:04
  • So you need a binding proxy then. – mm8 May 27 '19 at 14:10
  • Hi, I actually managed to solve it by adding a to the Datagrid. It basically adds a second row to each row of the DataGrid which can be hidden or showed. In this row then I added a grid to match the row's column composition and then it worked as planned. A bit tricky, the solution in VB6 was easier though,, – Marco Perrone Feb 03 '21 at 16:58

0 Answers0