Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 52 additions & 12 deletions src/Wpf.Ui/Controls/CheckBox/CheckBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<system:Double x:Key="CheckBoxIconSize">14</system:Double>
<system:Double x:Key="CheckBoxHeight">22</system:Double>
<system:Double x:Key="CheckBoxWidth">22</system:Double>
<system:TimeSpan x:Key="CheckBoxAnimationOffset">00:00:00.250</system:TimeSpan>
<Duration x:Key="CheckBoxAnimationDuration">00:00:00.250</Duration>
<converters:AnimationFactorToValueConverter x:Key="CheckBoxAnimationFactorToValueConverter" />
<converters:ClipConverter x:Key="ClipConverter" />

<Style x:Key="DefaultCheckBoxStyle" TargetType="{x:Type CheckBox}">
<!-- Universal WPF UI focus -->
Expand Down Expand Up @@ -78,18 +82,28 @@
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}">
<Grid>
<controls:SymbolIcon
x:Name="ControlIcon"
Margin="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="{StaticResource CheckBoxIconSize}"
FontWeight="Bold"
Foreground="{DynamicResource CheckBoxCheckGlyphForeground}"
Symbol="Checkmark48"
Visibility="Collapsed" />
</Grid>
<controls:SymbolIcon
x:Name="ControlIcon"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="{DynamicResource CheckBoxIconSize}"
FontWeight="Bold"
Foreground="{DynamicResource CheckBoxCheckGlyphForeground}"
Symbol="Checkmark48"
Visibility="Collapsed">
<controls:SymbolIcon.Clip>
<MultiBinding Converter="{StaticResource ClipConverter}">
<MultiBinding.Bindings>
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
<Binding Path="Tag" RelativeSource="{RelativeSource Self}" />
</MultiBinding.Bindings>
</MultiBinding>
</controls:SymbolIcon.Clip>
<controls:SymbolIcon.Tag>
<system:Double>1</system:Double>
</controls:SymbolIcon.Tag>
</controls:SymbolIcon>
</Border>
</Border>
</BulletDecorator.Bullet>
Expand Down Expand Up @@ -119,7 +133,33 @@
<Setter TargetName="ControlIcon" Property="Visibility" Value="Visible" />
<Setter TargetName="ControlBorderIconPresenter" Property="Background" Value="{DynamicResource CheckBoxCheckBackgroundFillChecked}" />
<Setter TargetName="StrokeBorder" Property="BorderBrush" Value="{DynamicResource CheckBoxCheckBorderBrush}" />
<Trigger.EnterActions>
<BeginStoryboard Name="SlideIn">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="ControlIcon"
Storyboard.TargetProperty="Tag"
From="0"
To="1"
Duration="{StaticResource CheckBoxAnimationDuration}">
<DoubleAnimation.EasingFunction>
<CubicEase EasingMode="EaseOut" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
<!-- Skip the animation when it becomes visible -->
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<SeekStoryboard BeginStoryboardName="SlideIn" Offset="{StaticResource CheckBoxAnimationOffset}" />
</Trigger.EnterActions>
</Trigger>
<!-- Skip the animation on load -->
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<SeekStoryboard BeginStoryboardName="SlideIn" Offset="{StaticResource CheckBoxAnimationOffset}" />
</EventTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
Expand Down
34 changes: 34 additions & 0 deletions src/Wpf.Ui/Converters/ClipConverter
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Windows.Data;

namespace Wpf.Ui.Converters;

public class ClipConverter : IMultiValueConverter
{
/// <inheritdoc />
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length != 3)
{
return null;
}

if (values[0] is not double width || values[1] is not double height || values[2] is not double percentage)
{
return null;
}

double clippedWidth = width * percentage;
return new RectangleGeometry(new Rect(0, 0, clippedWidth, height));
}

/// <inheritdoc />
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}