I want to to show the duration in minutes on my control but I don't want it to show up as with decimal numbers (eg, 65 instead of 65.94503).
我想在我的控制中以分钟显示持续时间,但我不希望它显示为十进制数字(例如,65而不是65.94503)。
<TextBlock Text="{Binding Duration.TotalMinutes, StringFormat=\{0\} minutes}" />
How can I do it?
我该怎么做?
2 个解决方案
#1
8
If you want an integer to display, I think that all you need to do is set the StringFormat property as follows:
如果要显示整数,我认为您需要做的就是设置StringFormat属性,如下所示:
<TextBlock Text="{Binding Duration.TotalMinutes, StringFormat=N0}"/>
#2
1
Do that in code instead of the markup. You can unit test that easily. Make TotalMinutes a string or int instead and format it in the ViewModel.
在代码而不是标记中执行此操作。您可以轻松进行单元测试。使TotalMinutes成为字符串或int,并在ViewModel中对其进行格式化。
#1
8
If you want an integer to display, I think that all you need to do is set the StringFormat property as follows:
如果要显示整数,我认为您需要做的就是设置StringFormat属性,如下所示:
<TextBlock Text="{Binding Duration.TotalMinutes, StringFormat=N0}"/>
#2
1
Do that in code instead of the markup. You can unit test that easily. Make TotalMinutes a string or int instead and format it in the ViewModel.
在代码而不是标记中执行此操作。您可以轻松进行单元测试。使TotalMinutes成为字符串或int,并在ViewModel中对其进行格式化。