1
\$\begingroup\$

I have created a "wrapper" for a button that "pulses" until the user presses the button. The implementation that I came up with is below, but I'm sure there's a better approach.

<UserControl x:Class="Foundation.Common.Controls.Wpf.FoundationGlowButtonWrapper"
         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"
         mc:Ignorable="d"
         d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Template>
    <ControlTemplate TargetType="UserControl">
        <Border x:Name="AnimatedColorButton" BorderThickness="2" BorderBrush="Gold" Margin="-2,0,0,0">
            <Border.Triggers>
                <EventTrigger RoutedEvent="Border.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="AnimatedColorButton"
                                                         Storyboard.TargetProperty="BorderBrush.Opacity"
                                                         RepeatBehavior="Forever"
                                                         AutoReverse="True"
                                                         To="0.0"
                                                         Duration="0:0:0.7" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Brushes.Transparent}" />
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Border.Triggers>
            <ContentPresenter Content="{TemplateBinding Content}" />
        </Border>
    </ControlTemplate>
</UserControl.Template>

XAML

 <wpf:FoundationGlowButtonWrapper>
      <telerik:RadButton />
 </wpf:FoundationGlowButtonWrapper>
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.