question

MojtabaHakim-8125 avatar image
0 Votes"
MojtabaHakim-8125 asked HuiLiu-MSFT answered

How to Bind Color of VerticalGridLinesBrush to color of a Background Button in WPF?

I'm using C# WPF and MaterialDesign Theme,

the Color Binding works as well, but I want to bind the Opacity property of VerticalGridLinesBrush to the Opacity property of that button

why-color-binding-doesnt-work-for-horizontalgridlinesbrush-in-datagrid-in-wpf


dotnet-csharpwindows-wpfdotnet-wpf-xaml
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

HuiLiu-MSFT avatar image
1 Vote"
HuiLiu-MSFT answered

The type of Background property of Control is Brush. There are a variety of Brushes and SolidColorBrush is one of them.
For the current value of Background to be SolidColorBrush, its Color property can be referenced in the binding.

 <StackPanel>
         <Slider Width="200" Minimum="0" Maximum="1" Value="{Binding ElementName=MY_BUTTON, Path=Opacity}"/>
                 <Button x:Name="MY_BUTTON"   Content="button"  Width="100" Height="50" Background="Red"/>
           <DataGrid>
             <DataGrid.HorizontalGridLinesBrush>
                             <SolidColorBrush Color="{Binding ElementName=MY_BUTTON,Path=Background.Color}"  Opacity="{Binding ElementName=MY_BUTTON,Path=Opacity}"/>
                         </DataGrid.HorizontalGridLinesBrush>
     ...
     </DataGrid>
 </StackPanel>

The result:
263283-3.gif


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




3.gif (253.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.