WPF:写入转换器,更新StopWatch Label而不是Timer

时间:2018-01-08 08:57:33

标签: wpf converter

所以我通过Label更新了简单的Timer

<Label Name="lblElapsedTime"
       Content="{Binding Converter={StaticResource ElapsedTimeConverter}}"/>

计时器勾选:

StopWatch StopWatch = new StopWatch();
private void progressTimer_Tick(object sender, EventArgs e)
{ 
    lblElapsedTime.Content = string.Format("{0:00}:{1:00}:{2:00}:{3:00}:{4:00}",
    StopWatch.Elapsed.Days,
    StopWatch.Elapsed.Hours,
    StopWatch.Elapsed.Minutes,
    StopWatch.Elapsed.Seconds,
    StopWatch.Elapsed.Milliseconds / 10);
}

现在我想替换这个Timer,也可以写简单的Converter来更新我的Label。 任何想法如何实现这个?

目前我在Window.Resources内写了这个:

<Convertors:ElapsedTimeConverter x:Key="ElapsedTimeConverter"/>

我当然有Converter,但是在没有StopWatch的情况下重新启动Timer是否可以更新?

这是我的转换:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return "";
        }

问题在于,虽然我将此Convert绑定到我的Label,但此转换甚至没有执行。

0 个答案:

没有答案