How do I set the pressed background color of a StyleManager-stylized, MS Button?

0 Answers 42 Views
Buttons Styling
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Joe asked on 27 Oct 2023, 05:44 PM
I use the Windows8Touch Theme and the StyleManager (so the binaries with XAML) to style my Telerik app.  I also follow the Telerik instrructions on how to apply the theme to standard Microsoft controls, like `System.Windows.Controls.Button`

    https://docs.telerik.com/devtools/wpf/styling-and-appearance/how-to/styling-apperance-themes-mscontrols

I use this technique to style the generic Button control and it works well.  Here is the relevant line in my default Button style

        <Setter Property="telerik:StyleManager.Theme" Value="Windows8Touch"/>


But now I have a case in which I want to give my button a transparent background but otherwise have it use the Telerik theming.  This seems like it would be easy:  Just set the `Background` property to `{x:Static Brushes.Transparent}` and it should work fine, right?

And that does look great.  Right up until I push the button.  When I push it, the background changes from transparent to... my default app background.  I want it to stay transparentd

Is there a simple property I can set or a style change I can make to achieve this.  I would prefer to avoid having to write a ControlTemplate for the button.

When I looked at the Telerik XAML, it appeared that I might be able to set a property like `mat:MaterialAssist.PressedBrush`

        <Setter Property="mat:MaterialAssist.PressedBrush" Value="Transparent"/>


or perhaps use `ThemeHelper.SetPressedBackgroundBrush` to achieve what I want


            `ThemeHelper.SetPressedBackgroundBrush(button, Brushes.Transparent);`


but neither of those two attempts made any difference.
Dinko
Telerik team
commented on 01 Nov 2023, 05:47 AM

Hello Joe,

To achieve this requirement and change the RadButton background color when it is pressed, you can extract and modify the Control Template of the RadButton. You can edit the VisualState with x:Name="Pressed" and add new SolidColorBrush color.

<VisualState x:Name="Pressed">
	<Storyboard>
		<ObjectAnimationUsingKeyFrames Storyboard.TargetName="OuterPressedBorder" Storyboard.TargetProperty="Background">
			<DiscreteObjectKeyFrame KeyTime="0">
				<DiscreteObjectKeyFrame.Value>
					<SolidColorBrush Color="#FF0000"/>
				</DiscreteObjectKeyFrame.Value>
			</DiscreteObjectKeyFrame>
		</ObjectAnimationUsingKeyFrames>
	</Storyboard>
</VisualState>

For your convenience I prepared a sample solution and a short video where this behavior is implemented.

No answers yet. Maybe you can help?

Tags
Buttons Styling
Asked by
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or