IsPressed Trigger for Custom User Control (WPF)
I've created a custom control for a button for my application. Everything's gone perfectly until I needed to establish a "IsPressed" trigger. I understand that the object isn't a button but I can't seem to find a way to get an inheritance from Button to my custom user control so I can used the "IsPressed" trigger. I hope this is making sense... How can I establish a trigger for "IsPressed" or something similar so that then a user presses the button, the background color changes.
My code as of now:
User Control
<UserControl x:Class="Tool_Management_System.Controls.NavBarButton" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Tool_Management_System.Controls" mc:Ignorable="d" d:DesignHeight="25" d:DesignWidth="150"> <Border x:Name="Body" Background="Transparent"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" MaxWidth="25"/> <ColumnDefinition Width="3*"/> </Grid.ColumnDefinitions> <Image x:Name="ButtonIcon" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="HighQuality"/> <TextBlock x:Name="ButtonText" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center"/> </Grid> </Border> </UserControl>
User Control Styling
<Style x:Key="NavBarButton" TargetType="Controls:NavBarButton"> <Setter Property="Height" Value="25"/> <Setter Property="Background" Value="#202020"/> <Setter Property="BorderBrush" Value="#000000"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Margin" Value="0,0,-1,-1"/> <Setter Property="FontSize" Value="10"/> <Setter Property="FontFamily" Value="Tahoma"/> <Setter Property="Foreground" Value="#DEDEDE"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Trigger.EnterActions> <BeginStoryboard> <Storyboard> <ColorAnimation Duration="0:0:0.25" Storyboard.TargetProperty="Background.Color" To="#80B45A00"/> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard> <Storyboard> <ColorAnimation Duration="0:0:0.25" Storyboard.TargetProperty="Background.Color" To="#202020"/> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </Style.Triggers> </Style>
0 comments:
Post a Comment