diff --git a/README.md b/README.md
index ff539909..02b72924 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@
[https://handyorg.github.io/handycontrol/](https://handyorg.github.io/handycontrol/)
### 赞助
-如果您觉得HandyControl还不错,并且刚好有些闲钱,那么可以选择以下两种方式来赞助:
+如果您觉得HandyControl还不错,并且刚好有些闲钱,那么可以选择以下两种方式来赞助(记得入群联系我们呀~~):
* [以HandyControl的名义为慈善事业做贡献](http://www.chinacharityfederation.org/ConfirmDonation/0.html?zhijie=3)
@@ -54,6 +54,7 @@
+
## Special thanks to
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/StepBarDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/StepBarDemoCtl.xaml
index dbce1495..0c230a0b 100644
--- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/StepBarDemoCtl.xaml
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/StepBarDemoCtl.xaml
@@ -18,7 +18,7 @@
-
+
diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/StepBarDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/StepBarDemoViewModel.cs
index 8c2032c1..49d03a53 100644
--- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/StepBarDemoViewModel.cs
+++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/StepBarDemoViewModel.cs
@@ -16,6 +16,18 @@ namespace HandyControlDemo.ViewModel
{
public StepBarDemoViewModel(DataService dataService) => DataList = dataService.GetStepBarDemoDataList();
+ private int _stepIndex;
+
+ public int StepIndex
+ {
+ get => _stepIndex;
+#if netle40
+ set => Set(nameof(StepIndex), ref _stepIndex, value);
+#else
+ set => Set(ref _stepIndex, value);
+#endif
+ }
+
///
/// 下一步
///
diff --git a/src/Shared/HandyControl_Shared/Controls/StepBar/StepBar.cs b/src/Shared/HandyControl_Shared/Controls/StepBar/StepBar.cs
index 4a085542..e4f7396c 100644
--- a/src/Shared/HandyControl_Shared/Controls/StepBar/StepBar.cs
+++ b/src/Shared/HandyControl_Shared/Controls/StepBar/StepBar.cs
@@ -18,6 +18,8 @@ namespace HandyControl.Controls
{
private ProgressBar _progressBarBack;
+ private int _oriStepIndex = -1;
+
#region Constants
private const string ElementProgressBarBack = "PART_ProgressBarBack";
@@ -46,19 +48,14 @@ namespace HandyControl.Controls
}
}
- if (StepIndex < count)
+ if (_oriStepIndex > 0)
{
- for (var i = 0; i < StepIndex; i++)
- {
- if (ItemContainerGenerator.ContainerFromIndex(i) is StepBarItem stepBarItem)
- {
- stepBarItem.Status = StepStatus.Complete;
- }
- }
- if (ItemContainerGenerator.ContainerFromIndex(StepIndex) is StepBarItem item)
- {
- item.Status = StepStatus.UnderWay;
- }
+ StepIndex = _oriStepIndex;
+ _oriStepIndex = -1;
+ }
+ else
+ {
+ OnStepIndexChanged(StepIndex);
}
}
}
@@ -85,12 +82,64 @@ namespace HandyControl.Controls
}
public static readonly DependencyProperty StepIndexProperty = DependencyProperty.Register(
- "StepIndex", typeof(int), typeof(StepBar), new PropertyMetadata(ValueBoxes.Int0Box));
+ "StepIndex", typeof(int), typeof(StepBar), new FrameworkPropertyMetadata(ValueBoxes.Int0Box,
+ FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnStepIndexChanged, CoerceStepIndex));
+
+ private static object CoerceStepIndex(DependencyObject d, object basevalue)
+ {
+ var ctl = (StepBar)d;
+ var stepIndex = (int) basevalue;
+ if (ctl.Items.Count == 0 && stepIndex > 0)
+ {
+ ctl._oriStepIndex = stepIndex;
+ return ValueBoxes.Int0Box;
+ }
+
+ return stepIndex < 0
+ ? ValueBoxes.Int0Box
+ : stepIndex >= ctl.Items.Count
+ ? ctl.Items.Count == 0 ? 0 : ctl.Items.Count - 1
+ : basevalue;
+ }
+
+ private static void OnStepIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var ctl = (StepBar) d;
+ ctl.OnStepIndexChanged((int)e.NewValue);
+ }
+
+ private void OnStepIndexChanged(int stepIndex)
+ {
+ for (var i = 0; i < stepIndex; i++)
+ {
+ if (ItemContainerGenerator.ContainerFromIndex(i) is StepBarItem stepItemFinished)
+ {
+ stepItemFinished.Status = StepStatus.Complete;
+ }
+ }
+
+ for (var i = stepIndex + 1; i < Items.Count; i++)
+ {
+ if (ItemContainerGenerator.ContainerFromIndex(i) is StepBarItem stepItemFinished)
+ {
+ stepItemFinished.Status = StepStatus.Waiting;
+ }
+ }
+
+ if (ItemContainerGenerator.ContainerFromIndex(stepIndex) is StepBarItem stepItemSelected)
+ stepItemSelected.Status = StepStatus.UnderWay;
+ _progressBarBack?.BeginAnimation(RangeBase.ValueProperty, AnimationHelper.CreateAnimation(stepIndex));
+
+ RaiseEvent(new FunctionEventArgs(StepChangedEvent, this)
+ {
+ Info = stepIndex
+ });
+ }
public int StepIndex
{
- get => (int)GetValue(StepIndexProperty);
- protected set => SetValue(StepIndexProperty, value);
+ get => (int)GetValue(StepIndexProperty);
+ set => SetValue(StepIndexProperty, value);
}
public static readonly DependencyProperty DockProperty = DependencyProperty.Register(
@@ -128,42 +177,8 @@ namespace HandyControl.Controls
}
}
- public void Next()
- {
- StepIndex++;
- if (StepIndex >= Items.Count)
- {
- StepIndex = Items.Count - 1;
- return;
- }
- RaiseEvent(new FunctionEventArgs(StepChangedEvent, this)
- {
- Info = StepIndex
- });
- if (ItemContainerGenerator.ContainerFromIndex(StepIndex - 1) is StepBarItem stepItemFinished)
- stepItemFinished.Status = StepStatus.Complete;
- if (ItemContainerGenerator.ContainerFromIndex(StepIndex) is StepBarItem stepItemSelected)
- stepItemSelected.Status = StepStatus.UnderWay;
- _progressBarBack?.BeginAnimation(RangeBase.ValueProperty, AnimationHelper.CreateAnimation(StepIndex));
- }
+ public void Next() => StepIndex++;
- public void Prev()
- {
- StepIndex--;
- if (StepIndex < 0)
- {
- StepIndex = 0;
- return;
- }
- RaiseEvent(new FunctionEventArgs(StepChangedEvent, this)
- {
- Info = StepIndex
- });
- if (ItemContainerGenerator.ContainerFromIndex(StepIndex + 1) is StepBarItem stepItemWaiting)
- stepItemWaiting.Status = StepStatus.Waiting;
- if (ItemContainerGenerator.ContainerFromIndex(StepIndex) is StepBarItem stepItemSelected)
- stepItemSelected.Status = StepStatus.UnderWay;
- _progressBarBack?.BeginAnimation(RangeBase.ValueProperty, AnimationHelper.CreateAnimation(StepIndex));
- }
+ public void Prev() => StepIndex--;
}
}
\ No newline at end of file