mardi 24 juillet 2018

is there a hack for getting the private key of a read only dependency property?

In WPF, I want to control when a button is pressed from C#. In order to achieve this I created a style:

<Style TargetType="Button">
    <Style.Triggers>
        <Trigger Property="IsPressed" Value="True">
            <Setter Property="Background" Value="Green"/>
            ... other styling
            </Setter>
        </Trigger>
    </Style.Triggers>
</Style>

and then I was going to set IsPressed myself when I wanted it to trigger.

However, System.Windows.Media.ButtonBase.IsPressed is a read-only dependency property. This means that you can't modify it's value from outside the ButtonBase class. You can learn more about read-only dependency properties at https://www.telerik.com/blogs/wpf-read-only-dependency-properties.

I think what I need to do is call myButton.SetValue(put private IsPressed Key here, true);

Is there any way to get a private dependency property key from outside the class? Using Reflection? Using something else?





Aucun commentaire:

Enregistrer un commentaire