|
<UserControl x:Class="App.Controls.BusyButton" |
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|
xmlns:local="using:App.Controls" |
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|
mc:Ignorable="d" |
|
d:DesignHeight="300" |
|
d:DesignWidth="400" |
|
HorizontalContentAlignment="Stretch" |
|
VerticalContentAlignment="Stretch" |
|
MinWidth="32" |
|
MinHeight="32"> |
|
<UserControl.Resources> |
|
<local:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> |
|
<!-- Duplicate of the Default button template --> |
|
<ControlTemplate x:Key="ButtonControlDefaultTemplate" |
|
TargetType="Button"> |
|
<Grid x:Name="RootGrid" |
|
Background="{TemplateBinding Background}" |
|
CornerRadius="5"> |
|
<VisualStateManager.VisualStateGroups> |
|
<VisualStateGroup x:Name="CommonStates"> |
|
<VisualState x:Name="Normal"> |
|
<Storyboard> |
|
<PointerUpThemeAnimation Storyboard.TargetName="RootGrid" /> |
|
</Storyboard> |
|
</VisualState> |
|
<VisualState x:Name="PointerOver"> |
|
<Storyboard> |
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" |
|
Storyboard.TargetName="ContentPresenter"> |
|
<DiscreteObjectKeyFrame KeyTime="0" |
|
Value="{ThemeResource SystemControlHighlightBaseMediumLowBrush}" /> |
|
</ObjectAnimationUsingKeyFrames> |
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" |
|
Storyboard.TargetName="ContentPresenter"> |
|
<DiscreteObjectKeyFrame KeyTime="0" |
|
Value="{ThemeResource SystemControlHighlightBaseHighBrush}" /> |
|
</ObjectAnimationUsingKeyFrames> |
|
<PointerUpThemeAnimation Storyboard.TargetName="RootGrid" /> |
|
</Storyboard> |
|
</VisualState> |
|
<VisualState x:Name="Pressed"> |
|
<Storyboard> |
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" |
|
Storyboard.TargetName="RootGrid"> |
|
<DiscreteObjectKeyFrame KeyTime="0" |
|
Value="{ThemeResource SystemControlBackgroundBaseMediumLowBrush}" /> |
|
</ObjectAnimationUsingKeyFrames> |
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" |
|
Storyboard.TargetName="ContentPresenter"> |
|
<DiscreteObjectKeyFrame KeyTime="0" |
|
Value="{ThemeResource SystemControlHighlightTransparentBrush}" /> |
|
</ObjectAnimationUsingKeyFrames> |
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" |
|
Storyboard.TargetName="ContentPresenter"> |
|
<DiscreteObjectKeyFrame KeyTime="0" |
|
Value="{ThemeResource SystemControlHighlightBaseHighBrush}" /> |
|
</ObjectAnimationUsingKeyFrames> |
|
<PointerDownThemeAnimation Storyboard.TargetName="RootGrid" /> |
|
</Storyboard> |
|
</VisualState> |
|
<VisualState x:Name="Disabled"> |
|
<Storyboard> |
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" |
|
Storyboard.TargetName="RootGrid"> |
|
<DiscreteObjectKeyFrame KeyTime="0" |
|
Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" /> |
|
</ObjectAnimationUsingKeyFrames> |
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" |
|
Storyboard.TargetName="ContentPresenter"> |
|
<DiscreteObjectKeyFrame KeyTime="0" |
|
Value="{ThemeResource SystemControlDisabledBaseMediumLowBrush}" /> |
|
</ObjectAnimationUsingKeyFrames> |
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" |
|
Storyboard.TargetName="ContentPresenter"> |
|
<DiscreteObjectKeyFrame KeyTime="0" |
|
Value="{ThemeResource SystemControlDisabledTransparentBrush}" /> |
|
</ObjectAnimationUsingKeyFrames> |
|
</Storyboard> |
|
</VisualState> |
|
</VisualStateGroup> |
|
</VisualStateManager.VisualStateGroups> |
|
<ContentPresenter x:Name="ContentPresenter" |
|
AutomationProperties.AccessibilityView="Raw" |
|
BorderBrush="{TemplateBinding BorderBrush}" |
|
BorderThickness="{TemplateBinding BorderThickness}" |
|
ContentTemplate="{TemplateBinding ContentTemplate}" |
|
ContentTransitions="{TemplateBinding ContentTransitions}" |
|
Content="{TemplateBinding Content}" |
|
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" |
|
Padding="{TemplateBinding Padding}" |
|
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" /> |
|
</Grid> |
|
</ControlTemplate> |
|
</UserControl.Resources> |
|
<Grid> |
|
<Button x:Name="MainButton" |
|
Content="{x:Bind ButtonContent, Mode=OneWay}" |
|
Style="{x:Bind ButtonStyle, Mode=OneWay}" |
|
Template="{x:Bind ButtonTemplate, Mode=OneWay}" |
|
HorizontalAlignment="{x:Bind HorizontalContentAlignment, Mode=OneWay}" |
|
VerticalAlignment="{x:Bind VerticalContentAlignment, Mode=OneWay}" |
|
Command="{x:Bind ButtonCommand, Mode=OneWay}" |
|
CommandParameter="{x:Bind ButtonCommandParameter, Mode=OneWay}" /> |
|
|
|
<Grid x:Name="BusyGrid" |
|
Visibility="{x:Bind IsBusy, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}"> |
|
<Grid.Background> |
|
<SolidColorBrush Color="{ThemeResource SystemAltHighColor}" |
|
Opacity=".3" /> |
|
</Grid.Background> |
|
<ProgressRing x:Name="BusyRing" |
|
VerticalAlignment="Stretch" |
|
HorizontalAlignment="Stretch" |
|
Margin="10" |
|
IsActive="{x:Bind IsBusy, Mode=OneWay}" |
|
Style="{x:Bind ProgressRingStyle, Mode=OneWay}" /> |
|
</Grid> |
|
</Grid> |
|
</UserControl> |
Idea here is to have a Button that makes itself impervious to multi-click by the user while it's executing a command. As a bonus, let's have a
ProgressRing
show up on it while it's working!