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

Mojtaba_Hakim 281 Reputation points
2022-11-22T22:25:59.327+00:00

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

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,666 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,197 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
760 questions
0 comments No comments
{count} votes

Accepted answer
  1. Hui Liu-MSFT 37,946 Reputation points Microsoft Vendor
    2022-11-23T02:39:40.197+00:00

    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful