Skip to content

Commit

Permalink
feature/Change the CornerRadius property of ButtonHelper to CornerRad…
Browse files Browse the repository at this point in the history
…iusX
  • Loading branch information
Mochengvia committed Jan 10, 2025
1 parent 6f512db commit 7fecd36
Show file tree
Hide file tree
Showing 25 changed files with 1,596 additions and 191 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Events\FormGroupCollectSizeEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Events\FormGroupCollectSizeEventHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ClassNameHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ElementStateManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\VisualStateHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Implements\NoticeHandlerImpl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Implements\PendingHandlerImpl.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Setter Property="Margin"
Value="0,0,5,0" />
<Setter Property="GlyphBrush"
Value="{Binding Path=(i:VisualStateHelper.Foreground), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
Value="{Binding Path=(i:ElementStateManager.Foreground), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
<Setter Property="Width"
Value="{Binding FontSize, Converter={x:Static pw:Converters.DoublePlusConverter}, ConverterParameter=6, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
<Setter Property="Height"
Expand All @@ -23,9 +23,9 @@

<Style x:Key="{x:Static rs:StyleKeys.ButtonStyle}"
TargetType="Button">
<Setter Property="i:VisualStateHelper.Regist"
<Setter Property="i:ElementStateManager.Regist"
Value="True" />
<Setter Property="i:VisualStateHelper.IsHover"
<Setter Property="i:ElementStateManager.IsHover"
Value="{Binding IsMouseOver, RelativeSource={RelativeSource Self}, Mode=OneWay}" />
<Setter Property="local:IconHelper.FontFamily"
Value="{Binding IconFontFamily, Source={x:Static local:GlobalSettings.Setting}}" />
Expand All @@ -34,7 +34,7 @@
<Setter Property="local:IconHelper.Margin"
Value="0,0,5,0" />
<Setter Property="local:IconHelper.Foreground"
Value="{Binding Path=(i:VisualStateHelper.Foreground), RelativeSource={RelativeSource Self}, Mode=OneWay}" />
Value="{Binding Path=(i:ElementStateManager.Foreground), RelativeSource={RelativeSource Self}, Mode=OneWay}" />
<Setter Property="FocusVisualStyle"
Value="{Binding FocusVisualStyle, Source={x:Static local:GlobalSettings.Setting}}" />
<Setter Property="local:ButtonHelper.HoverBackground"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,33 @@

<ControlTemplate x:Key="{x:Static irs:TemplateKeys.ButtonPendingTemplate}"
TargetType="Button">
<Grid Margin="{Binding Path=(i:VisualStateHelper.Margin), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}">
<Grid Margin="{Binding Path=(i:ElementStateManager.Margin), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}">
<Border x:Name="BdrContainer"
i:VisualStateHelper.IsClickEffectPressed="{Binding IsPressed, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Background="{Binding Path=(i:VisualStateHelper.Background), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
BorderBrush="{Binding Path=(i:VisualStateHelper.BorderBrush), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
BorderThickness="{Binding Path=(i:VisualStateHelper.BorderThickness), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
CornerRadius="{Binding Path=(i:VisualStateHelper.CornerRadius), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Effect="{Binding Path=(i:VisualStateHelper.Effect), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
<Border Margin="{Binding Path=(i:VisualStateHelper.BorderThickness), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
i:ElementStateManager.IsClickEffectPressed="{Binding IsPressed, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Background="{Binding Path=(i:ElementStateManager.Background), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
BorderBrush="{Binding Path=(i:ElementStateManager.BorderBrush), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
BorderThickness="{Binding Path=(i:ElementStateManager.BorderThickness), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Effect="{Binding Path=(i:ElementStateManager.Effect), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}">
<Border.CornerRadius>
<MultiBinding Converter="{x:Static pw:Converters.CornerRadiusXToCornerRadiusConverter}">
<Binding Path="(i:ElementStateManager.CornerRadius)"
RelativeSource="{RelativeSource TemplatedParent}"
Mode="OneWay" />
<Binding Path="ActualWidth"
RelativeSource="{RelativeSource TemplatedParent}"
Mode="OneWay" />
<Binding Path="ActualHeight"
RelativeSource="{RelativeSource TemplatedParent}"
Mode="OneWay" />
</MultiBinding>
</Border.CornerRadius>
</Border>
<Border Margin="{Binding Path=(i:ElementStateManager.BorderThickness), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Padding="{TemplateBinding Padding}">
<DockPanel x:Name="DockContainer"
Margin="{Binding Path=(i:VisualStateHelper.BorderThickness), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
TextElement.Foreground="{Binding Path=(i:VisualStateHelper.Foreground), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
TextBlock.Foreground="{Binding Path=(i:VisualStateHelper.Foreground), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Margin="{Binding Path=(i:ElementStateManager.BorderThickness), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
TextElement.Foreground="{Binding Path=(i:ElementStateManager.Foreground), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
TextBlock.Foreground="{Binding Path=(i:ElementStateManager.Foreground), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
<local:Spin x:Name="SprPending"
Expand Down Expand Up @@ -105,19 +118,32 @@
<ControlTemplate x:Key="{x:Static irs:TemplateKeys.ButtonTemplate}"
TargetType="Button">
<Grid x:Name="GrdContainer"
Margin="{Binding Path=(i:VisualStateHelper.Margin), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}">
Margin="{Binding Path=(i:ElementStateManager.Margin), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}">
<Border x:Name="BdrContainer"
i:VisualStateHelper.IsClickEffectPressed="{Binding IsPressed, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Background="{Binding Path=(i:VisualStateHelper.Background), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
BorderBrush="{Binding Path=(i:VisualStateHelper.BorderBrush), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
BorderThickness="{Binding Path=(i:VisualStateHelper.BorderThickness), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
CornerRadius="{Binding Path=(i:VisualStateHelper.CornerRadius), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Effect="{Binding Path=(i:VisualStateHelper.Effect), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
<Border Margin="{Binding Path=(i:VisualStateHelper.BorderThickness), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
i:ElementStateManager.IsClickEffectPressed="{Binding IsPressed, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Background="{Binding Path=(i:ElementStateManager.Background), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
BorderBrush="{Binding Path=(i:ElementStateManager.BorderBrush), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
BorderThickness="{Binding Path=(i:ElementStateManager.BorderThickness), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Effect="{Binding Path=(i:ElementStateManager.Effect), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}">
<Border.CornerRadius>
<MultiBinding Converter="{x:Static pw:Converters.CornerRadiusXToCornerRadiusConverter}">
<Binding Path="(i:ElementStateManager.CornerRadius)"
RelativeSource="{RelativeSource TemplatedParent}"
Mode="OneWay" />
<Binding Path="ActualWidth"
RelativeSource="{RelativeSource TemplatedParent}"
Mode="OneWay" />
<Binding Path="ActualHeight"
RelativeSource="{RelativeSource TemplatedParent}"
Mode="OneWay" />
</MultiBinding>
</Border.CornerRadius>
</Border>
<Border Margin="{Binding Path=(i:ElementStateManager.BorderThickness), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Padding="{TemplateBinding Padding}">
<DockPanel x:Name="DockContainer"
TextElement.Foreground="{Binding Path=(i:VisualStateHelper.Foreground), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
TextBlock.Foreground="{Binding Path=(i:VisualStateHelper.Foreground), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
TextElement.Foreground="{Binding Path=(i:ElementStateManager.Foreground), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
TextBlock.Foreground="{Binding Path=(i:ElementStateManager.Foreground), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
<i:IconPresenter x:Name="IpIcon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void BeginAnimationStoryboard(DependencyObject obj,
#endregion

#region BeginBrushAnimationStoryboard
public static void BeginBrushAnimationStoryboard(DependencyObject obj,
public static void BeginBrushAnimationStoryboard(FrameworkElement element,
Dictionary<DependencyProperty, Brush> propertyValues,
TimeSpan? duration = null)
{
Expand All @@ -78,14 +78,14 @@ public static void BeginBrushAnimationStoryboard(DependencyObject obj,
To = propertyValue.Value,
Duration = duration ?? GlobalSettings.Setting.AnimationDuration,
};
Storyboard.SetTarget(anima, obj);
Storyboard.SetTarget(anima, element);
Storyboard.SetTargetProperty(anima, new PropertyPath(propertyValue.Key));
storyboard.Children.Add(anima);
}
storyboard.Begin();
}

public static void BeginBrushAnimationStoryboard(DependencyObject obj,
public static void BeginBrushAnimationStoryboard(FrameworkElement element,
Dictionary<DependencyProperty, object> propertyValues,
TimeSpan? duration = null)
{
Expand Down Expand Up @@ -122,14 +122,24 @@ public static void BeginBrushAnimationStoryboard(DependencyObject obj,
Duration = duration ?? GlobalSettings.Setting.AnimationDuration,
};
}
Storyboard.SetTarget(anima, obj);
if (propertyValue.Value is CornerRadiusX cornerRadiusXValue)
{
double baseValue = Math.Min((double)element.ActualWidth, (double)element.ActualHeight);
var toCornerRadius = cornerRadiusXValue.ToCornerRadius(baseValue, baseValue);
anima = new CornerRadiusXAnimation()
{
To = toCornerRadius,
Duration = duration ?? GlobalSettings.Setting.AnimationDuration,
};
}
Storyboard.SetTarget(anima, element);
Storyboard.SetTargetProperty(anima, new PropertyPath(propertyValue.Key));
storyboard.Children.Add(anima);
}
storyboard.Begin();
}

public static void BeginBrushAnimationStoryboard(DependencyObject obj,
public static void BeginBrushAnimationStoryboard(FrameworkElement element,
List<DependencyProperty> properties,
TimeSpan? duration = null)
{
Expand Down Expand Up @@ -159,7 +169,14 @@ public static void BeginBrushAnimationStoryboard(DependencyObject obj,
Duration = duration ?? GlobalSettings.Setting.AnimationDuration,
};
}
Storyboard.SetTarget(anima, obj);
else if (dp.PropertyType == typeof(CornerRadiusX))
{
anima = new CornerRadiusXAnimation()
{
Duration = duration ?? GlobalSettings.Setting.AnimationDuration,
};
}
Storyboard.SetTarget(anima, element);
Storyboard.SetTargetProperty(anima, new PropertyPath(dp));
storyboard.Children.Add(anima);
}
Expand Down
Loading

0 comments on commit 7fecd36

Please sign in to comment.