BSalita
BSalita

Reputation: 8961

How to bind Background color to another IsSelected Background

I want to bind the selected Background color of MyDataGrid to another IsSelected Background color so they share the same color. I'm thinking it can be done something like below. How can I do it?

                <DataGrid.Resources>
                    <Style TargetType="{x:Type DataGridCell}">
                        <Style.Triggers>
                            <Trigger Property="DataGridCell.IsSelected" Value="True">
                                <Setter Property="Background" Value="{Binding ElementName=OtherDataGrid, Path=??Background??" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.Resources>

Upvotes: 0

Views: 360

Answers (3)

Amit
Amit

Reputation: 939

You can create a brush in resources and refer that in both the data grids.

Like:

<Style.Triggers>
    <Trigger Property="DataGridCell.IsSelected" Value="True">
         <Setter Property="Background" Value="{StaticResource selectedCellBackground}" />
    </Trigger>
</Style.Triggers>

Upvotes: 1

Y.Yanavichus
Y.Yanavichus

Reputation: 2417

Another way is to declare a notify property in the view model and bind both colors to it.

Upvotes: 0

user572559
user572559

Reputation:

The best way to share the background is to use a StaticResource.

Upvotes: 1

Related Questions