Skip to content

Commit

Permalink
Improve StepBar
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Jan 9, 2025
1 parent a1bbb6d commit 041fe33
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
32 changes: 20 additions & 12 deletions dev/DevWinUI.Controls/Controls/StepBar/StepBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ public partial class StepBar : ItemsControl
private Border progressBarBorder;
private Grid rootGridVertical;
private int ItemsCount => Items.Count;
public ControlTemplate? HorizontalTemplate { get; set; }
public ControlTemplate? VerticalTemplate { get; set; }
public Style? HorizontalItemContainerStyle { get; set; }
public Style? VerticalItemContainerStyle { get; set; }

private ControlTemplate? HorizontalTemplate { get; set; }
private ControlTemplate? VerticalTemplate { get; set; }
private Style? HorizontalItemContainerStyle { get; set; }
private Style? VerticalItemContainerStyle { get; set; }
private ItemsPanelTemplate HorizontalItemsPanelTemplate { get; set; }
private ItemsPanelTemplate VerticalItemsPanelTemplate { get; set; }

private int _oriStepIndex = -1;
private void UpdateTemplate()
{
Expand All @@ -39,16 +41,22 @@ private void UpdateTemplate()
public StepBar()
{
if (Application.Current.Resources["StepBarHorizontalControlTemplate"] is ControlTemplate horizontalTemplate)
HorizontalTemplate = horizontalTemplate;
this.HorizontalTemplate = horizontalTemplate;

if (Application.Current.Resources["StepBarVerticalControlTemplate"] is ControlTemplate verticalTemplate)
VerticalTemplate = verticalTemplate;
this.VerticalTemplate = verticalTemplate;

if (Application.Current.Resources["StepBarItemHorizontalStyle"] is Style horizontalItemContainerStyle)
HorizontalItemContainerStyle = horizontalItemContainerStyle;
this.HorizontalItemContainerStyle = horizontalItemContainerStyle;

if (Application.Current.Resources["StepBarItemVerticalStyle"] is Style verticalItemContainerStyle)
VerticalItemContainerStyle = verticalItemContainerStyle;
this.VerticalItemContainerStyle = verticalItemContainerStyle;

if (Application.Current.Resources["StepBarHorizontalItemsPanelTemplate"] is ItemsPanelTemplate horizontalItemsPanelTemplate)
this.HorizontalItemsPanelTemplate = horizontalItemsPanelTemplate;

if (Application.Current.Resources["StepBarVerticalItemsPanelTemplate"] is ItemsPanelTemplate verticalItemsPanelTemplate)
this.VerticalItemsPanelTemplate = verticalItemsPanelTemplate;
}

protected override void OnApplyTemplate()
Expand Down Expand Up @@ -81,11 +89,11 @@ private void UpdateItemsPanel()

if (Orientation == Orientation.Horizontal)
{
ItemsPanel = (ItemsPanelTemplate)XamlReader.Load("<ItemsPanelTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'><UniformGrid xmlns='using:DevWinUI' Rows='1'/></ItemsPanelTemplate>");
ItemsPanel = HorizontalItemsPanelTemplate;
}
else
{
ItemsPanel = (ItemsPanelTemplate)XamlReader.Load("<ItemsPanelTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'><UniformGrid xmlns='using:DevWinUI' Columns='1'/></ItemsPanelTemplate>");
ItemsPanel = VerticalItemsPanelTemplate;
}
}

Expand Down Expand Up @@ -261,7 +269,7 @@ private void SetProgressBarValueWithAnimation(double toValue, int duration = 200
horizontalStoryboard.Children.Add(horizontalAnimation);
horizontalStoryboard.Begin();
}

private void UpdateProgressBarVisualStates()
{
VisualStateManager.GoToState(this, Status.ToString(), true);
Expand Down
9 changes: 9 additions & 0 deletions dev/DevWinUI.Controls/Themes/Styles/Controls/StepBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Setter Property="Padding" Value="10" />
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemHorizontalStyle}" />
<Setter Property="Template" Value="{StaticResource StepBarHorizontalControlTemplate}" />
<Setter Property="ItemsPanel" Value="{StaticResource StepBarHorizontalItemsPanelTemplate}" />
</Style>

<ControlTemplate x:Key="StepBarHorizontalControlTemplate"
Expand Down Expand Up @@ -467,4 +468,12 @@
</Setter>
</Style>

<ItemsPanelTemplate x:Key="StepBarHorizontalItemsPanelTemplate">
<dev:UniformGrid Rows="1" />
</ItemsPanelTemplate>

<ItemsPanelTemplate x:Key="StepBarVerticalItemsPanelTemplate">
<dev:UniformGrid Columns="1" />
</ItemsPanelTemplate>

</ResourceDictionary>

0 comments on commit 041fe33

Please sign in to comment.