在Windows 10移动应用程序中创建秒表计数器控件

时间:2015-11-13 00:52:36

标签: c# xaml windows-store-apps stopwatch windows-10-mobile

我目前正在使用Windows 10移动应用

我想制作一个这样的秒表: enter image description here

我遵循了本教程:Create a StopWatch Counter control in WPF(XAML)

但我正在使用Windows 10,所以我无法使用IMultiValueConverter

有任何建议可以帮助我解决这个问题..非常感谢你。

1 个答案:

答案 0 :(得分:1)

以下是您可以开始的内容 - in this post Arek Kubiak liked source to his arc,可以像以下一样使用:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" xmlns:arc="using:ArcControl">
    <Grid Width="80" Height="80">
        <arc:Arc Thickness="3" Fill="Blue"  PercentValue="{Binding Percent}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
        <TextBlock Text="{Binding Percent}" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </Grid>
</Grid>
代码背后的代码:

public sealed partial class MainPage : Page, INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    public void RaiseProperty(string name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));

    private int percent = 0;
    public int Percent
    {
        get { return percent; }
        set { percent = value; RaiseProperty(nameof(Percent)); }
    }

    private DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(0.25) };

    public MainPage()
    {
        this.InitializeComponent();
        this.DataContext = this;
        timer.Tick += (s, e) => { Percent++; if (Percent > 99) Percent = 0; };
        timer.Start();
    }
}

结果:enter image description here

当然,要使其更好,更符合您的需求,仍然需要做更多的工作,但是有很多关于圆形/径向控制的博客/帖子。您可以查看at this postthis blog和默认 ProgressBar 的样式。有了这些,您可以使用合适的 VisualStates 设计自己的控件,并且过渡看起来就像您想要的那样。