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

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

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


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,170 questions
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.
6,917 questions
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
556 questions
No comments
{count} votes

Accepted answer
  1. answered 2022-11-23T02:39:40.197+00:00
    Hui Liu-MSFT 14,556 Reputation points Microsoft Employee

    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.

            <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"/>  
                                <SolidColorBrush Color="{Binding ElementName=MY_BUTTON,Path=Background.Color}"  Opacity="{Binding ElementName=MY_BUTTON,Path=Opacity}"/>  

    The result:


    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.

    No comments

0 additional answers

Sort by: Most helpful