I have a DataGrid displaying bunch of Objects. Those objects have a property IsDetailsExpanded
and I want to bind the DataRows DetailsVisibility
property to that property.
My first approach works but requires some code-behind (which i would like to get rid of)
i handle the LoadingRow
event
void LoadingRowHandler(object sender, DataGridRowEventArgs e)
{
Binding b = new Binding()
{
Source = e.Row.DataContext,
Path = new PropertyPath("IsExpanded"),
Converter = (IValueConverter)Resources["BoolToVisi"],
Mode = BindingMode.TwoWay
};
e.Row.SetBinding(DataGridRow.DetailsVisibilityProperty, b);
}
i think there has to be a way to achieve something similar in XAML but i unfortunately i have not the slightest clue. Any ideas? suggestions?
You can use a Style for the DataGridRow
type, like so:
<DataGrid Name="dataGrid1" Margin="12,12,0,0">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="DetailsVisibility" Value="{Binding IsExpanded, Converter={StaticResource BoolToVisi}}" />
</Style>
</DataGrid.RowStyle>
</DataGrid>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With