Create a Stopwatch Counter Control in Windows 10 Mobile App

我只是一个虾纸丫 提交于 2019-12-08 12:26:59

问题


I'm currently working on Windows 10 Mobile App

And I want to make a stopwatch like this:

I followed this tutorial: Create a StopWatch Counter control in WPF(XAML)

But I'm working on Windows 10, so I can't use IMultiValueConverter

Any suggestion to help me go through this.. Thank you so much.


回答1:


Here is something with what you can start - in this post Arek Kubiak liked source to his arc which can be used for example like this:

<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>

code behind:

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();
    }
}

The result:

Of course it still needs much more work to make it better, fit your needs, but there are lots of blogs/posts about circular/radial controls. You can take a look at this post, this blog and default ProgressBar's style. With those you can design your own control with suitable VisualStates and transition that will look like you just want it.



来源:https://stackoverflow.com/questions/33684180/create-a-stopwatch-counter-control-in-windows-10-mobile-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!