update StepBar & readme

This commit is contained in:
NaBian committed 2020-03-28 14:27:13 +08:00
1 parent 31ee8e91f2
commit b7222be265
4 files changed
+81 -53

No files matched your search

+2 -1
View File
@@ -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 @@
<a href="https://github.com/MrZhangYuan" target="_blank"><img width="64px" src="https://avatars2.githubusercontent.com/u/16384123?s=64&v=4"></a>
<a href="https://github.com/YC946586" target="_blank"><img width="64px" src="https://avatars2.githubusercontent.com/u/49895722?s=64&v=4"></a>
<a href="https://github.com/wihalo" target="_blank"><img width="64px" src="https://avatars0.githubusercontent.com/u/26402999?s=64&v=4"></a>
<a href="https://github.com/startewho" target="_blank"><img width="64px" src="https://avatars0.githubusercontent.com/u/898009?s=64&v=4"></a>
## Special thanks to
@@ -18,7 +18,7 @@
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<hc:StepBar Grid.ColumnSpan="2">
<hc:StepBar Grid.ColumnSpan="2" StepIndex="{Binding StepIndex}">
<hc:StepBarItem Content="{x:Static langs:Lang.Register}"/>
<hc:StepBarItem Content="{x:Static langs:Lang.BasicInfo}"/>
<hc:StepBarItem Content="{x:Static langs:Lang.UploadFile}"/>
@@ -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
}
/// <summary>
/// 下一步
/// </summary>
@@ -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<int>(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<int>(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<int>(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--;
}
}