将秒转换为分钟:秒

Joh*_*lan 4 c# data-binding windows-phone-7

我试图TextBlock通过转换总秒数来绑定 a 的 Text 属性,即

1004 为分钟:秒,我可以成功地从 XML 中提取秒数,但我不知道如何使用 Getters 和 Setters,以便我可以将秒数转换为分钟:秒

我看了一下TimeSpan,我知道它可以满足我的要求,但我不知道如何编写 getter 和 setter,以便它将整数值(秒)转换为分钟:秒格式。

这是我目前在课堂上所拥有的

public class Stats 
{
 public TimeSpan Time {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激,

谢谢

约翰

shf*_*301 5

要将其作为财产来执行,您可以执行以下操作:

public class Stats {
   public TimeSpan Time { get; set; }
   public string TimeFormated { get { return Time.TotalMinutes + ":" + Time.Seconds; } }
}
Run Code Online (Sandbox Code Playgroud)

尽管您确实应该在 XAML 中执行此操作,因为所做的是布局:

<StackPanel Orientation="Horizontal">
  <TextBlock Text={Binding Time.TotalMinutes}" />
  <TextBlock Text=":" />
  <TextBlock Text=={Binding Time.Seconds}" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)