Skip to content

Commit c66fc7f

Browse files
committed
Add ItemClick event and AutoSelectOnItemClick proeprty in StepBar
1 parent a3f54c5 commit c66fc7f

4 files changed

Lines changed: 42 additions & 1 deletion

File tree

dev/DevWinUI.Controls/Controls/StepBar/StepBar.Property.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,13 @@ private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedE
148148
ctl.UpdateItems();
149149
}
150150
}
151+
152+
public bool AutoSelectOnItemClick
153+
{
154+
get => (bool)GetValue(AutoSelectOnItemClickProperty);
155+
set => SetValue(AutoSelectOnItemClickProperty, value);
156+
}
157+
158+
public static readonly DependencyProperty AutoSelectOnItemClickProperty =
159+
DependencyProperty.Register(nameof(AutoSelectOnItemClick), typeof(bool), typeof(StepBar), new PropertyMetadata(false));
151160
}

dev/DevWinUI.Controls/Controls/StepBar/StepBar.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics.CodeAnalysis;
2+
using Microsoft.UI.Xaml.Input;
23
using Microsoft.UI.Xaml.Markup;
34

45
namespace DevWinUI;
@@ -23,6 +24,8 @@ public partial class StepBar : ItemsControl
2324
private ItemsPanelTemplate HorizontalItemsPanelTemplate { get; set; }
2425
private ItemsPanelTemplate VerticalItemsPanelTemplate { get; set; }
2526
public event EventHandler<int> StepChanged;
27+
public event EventHandler<StepBarItemClickEventArgs>? ItemClick;
28+
2629
private int _oriStepIndex = -1;
2730
private void UpdateTemplate()
2831
{
@@ -313,7 +316,20 @@ private void UpdateProgressBarVisualStates()
313316
{
314317
VisualStateManager.GoToState(this, Status.ToString(), true);
315318
}
319+
private void OnItemTapped(object sender, TappedRoutedEventArgs e)
320+
{
321+
if (sender is StepBarItem stepBarItem)
322+
{
323+
int index = ItemContainerGenerator.IndexFromContainer(stepBarItem);
324+
325+
ItemClick?.Invoke(this, new StepBarItemClickEventArgs(index, stepBarItem));
316326

327+
if (AutoSelectOnItemClick)
328+
{
329+
StepIndex = index;
330+
}
331+
}
332+
}
317333
public void Next() => StepIndex++;
318334
public void Prev() => StepIndex--;
319335
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace DevWinUI;
2+
public class StepBarItemClickEventArgs : EventArgs
3+
{
4+
public int Index { get; set; }
5+
public StepBarItem? ClickedItem { get; }
6+
7+
public StepBarItemClickEventArgs(int index, StepBarItem? clickedItem)
8+
{
9+
Index = index;
10+
ClickedItem = clickedItem;
11+
}
12+
}

dev/DevWinUI.Gallery/Views/Pages/Features/StepBarPage.xaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,21 @@
4444
<ComboBox x:Name="CmbHeaderDisplayMode"
4545
Header="Header Display Mode"
4646
ItemsSource="{x:Bind ViewModel.StepBarHeaderDisplayModeItems, Mode=OneWay}"
47-
SelectedIndex="3" />
47+
SelectedIndex="1" />
4848
<ComboBox x:Name="CmbDisplayMode"
4949
Header="Display Mode"
5050
ItemsSource="{x:Bind ViewModel.StepBarDisplayModeItems, Mode=OneWay}"
5151
SelectedIndex="0" />
5252
<ToggleSwitch x:Name="TGShowStepIndex"
5353
Header="Show StepIndex"
5454
IsOn="True" />
55+
<ToggleSwitch x:Name="TGAutoSelectOnItemClick"
56+
Header="Auto Select On Item Click"
57+
IsOn="True" />
5558
</StackPanel>
5659
</local:ControlExample.Pane>
5760
<dev:StepBar x:Name="StepBarSample"
61+
AutoSelectOnItemClick="{x:Bind TGAutoSelectOnItemClick.IsOn, Mode=OneWay}"
5862
DisplayMode="{x:Bind ((dev:StepBarDisplayMode)CmbDisplayMode.SelectedItem), Mode=OneWay}"
5963
HeaderDisplayMode="{x:Bind ((dev:StepBarHeaderDisplayMode)CmbHeaderDisplayMode.SelectedItem), Mode=OneWay}"
6064
Orientation="{x:Bind ((Orientation)CmbOrientation.SelectedItem), Mode=OneWay}"

0 commit comments

Comments
 (0)