Set triggers for changing color of Icon in button
Posted: 08 Jul 2019, 15:45
Hi!
I'm new to XAML. Not a programmer, but artist/designer.
I need help with XAML-coding of button-template. It's a template which is used to display a button with a transparent background and a icon.
I want to be able to set triggers for the buttons so that the icon changes color when button is pressed.
The icon derives from a resource dictionary and is defined as a ControlTemplate like this:
The button is created like this:
The style 'IconStyle_default' is just there to determine the default colors for the icon.
My current ButtonTemplate looks like this:
How do I write a Button template that let's me set different states for the colors of the icon?
The ControlObect for the icon itself is not part of the ButtonTemplate. My best guess it that I need to connect the Properties for the Icon ControlObject Foreground and Background-color with the ContentPresenter. Is this possible to achieve?
I'm new to XAML. Not a programmer, but artist/designer.
I need help with XAML-coding of button-template. It's a template which is used to display a button with a transparent background and a icon.
I want to be able to set triggers for the buttons so that the icon changes color when button is pressed.
The icon derives from a resource dictionary and is defined as a ControlTemplate like this:
Code: Select all
<ResourceDictionary>
<ControlTemplate x:Key="home_ic" TargetType="{x:Type Control}">
<Viewbox>
<Canvas Width="90" Height="90">
<Path Fill="{TemplateBinding Background}" Data="F1 M 90.000,90.000 L 0.000,90.000 L 0.000,0.000 L 90.000,0.000 L 90.000,90.000 Z"/>
<Path Fill="{TemplateBinding Foreground}" Data="F1 M 71.000,39.461 L 71.000,70.674 L 52.800,70.674 L 52.800,49.874 L 37.200,49.874 L 37.200,70.674 L 19.000,70.674 L 19.000,39.474 L 45.000,18.674 L 71.000,39.461 Z"/>
</Canvas>
</Viewbox>
</ControlTemplate>
</ResourceDictionary>Code: Select all
<Button>
<Control Template="{StaticResource home_ic}" Style="{StaticResource IconStyle_default}" Foreground="#FFFFFFFF" Background="#00FFFFFF"/>
</Button>My current ButtonTemplate looks like this:
Code: Select all
<ControlTemplate x:Key="ImageButtonStyle" TargetType="{x:Type Button}">
<Grid x:Name="grid">
<Viewbox x:Name="Icon_viewbox" Width="Auto" Height="Auto">
<ContentPresenter x:Name="contentPresenter"/>
</Viewbox>
</Grid>
</ControlTemplate>The ControlObect for the icon itself is not part of the ButtonTemplate. My best guess it that I need to connect the Properties for the Icon ControlObject Foreground and Background-color with the ContentPresenter. Is this possible to achieve?