【发布时间】:2013-04-22 14:23:30
【问题描述】:
我正在尝试在热门应用栏中显示当前的 sysdatetime,但我想知道无论如何我可以在 XAML 中为 win 商店应用程序执行此操作。
【问题讨论】:
标签: xaml windows-runtime winrt-xaml
我正在尝试在热门应用栏中显示当前的 sysdatetime,但我想知道无论如何我可以在 XAML 中为 win 商店应用程序执行此操作。
【问题讨论】:
标签: xaml windows-runtime winrt-xaml
public class MainViewModel : INotifyPropertyChanged
{
private readonly DispatcherTimer _timer = new DispatcherTimer();
private string _resDateTime;
public string ResDateTime
{
get
{
return _resDateTime;
}
set
{
_resDateTime = value;
NotifyPropertyChanged("ResDateTime");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this,
new PropertyChangedEventArgs(propertyName));
}
}
public MainViewModel()
{
_timer.Tick += TimerOnTick;
_timer.Start();
}
private void TimerOnTick(object sender, object o)
{
ResDateTime = DateTime.Now.ToString();
}
}
添加到后面的代码
public MainPage()
{
this.InitializeComponent();
DataContext = new MainViewModel();
}
然后穿上xaml
<Page.TopAppBar>
<AppBar>
<TextBlock Text="{Binding ResDateTime}"></TextBlock>
</AppBar>
</Page.TopAppBar>
希望对你有帮助
【讨论】:
在您的页面中,您可以像这样设置 Page.TopAppBar 和 Page.BottomAppBar:
<Page.TopAppBar>
<AppBar>
<TextBlock Text="Your text" />
</AppBar>
</Page.TopAppBar>
从那里,您可以绑定 Text 属性(如果您使用 MVVM 模式),或者通过为 TextBlock 元素命名来简单地在页面后面的代码中分配一个值。
【讨论】: