0

トップアプリバーに現在のsysdatetimeを表示しようとしていますが、とにかく勝利ストアアプリのXAMLでそれを行うことができると思っていました.

4

2 に答える 2

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

それが役立つことを願っています

于 2013-04-23T08:53:57.580 に答える
1

ページでは、次のように Page.TopAppBar と Page.BottomAppBar を設定できます。

<Page.TopAppBar>
    <AppBar>
        <TextBlock Text="Your text" />
    </AppBar>
</Page.TopAppBar>

そこから、MVVM パターンを使用している場合は Text プロパティをバインドするか、TextBlock 要素に名前を付けて、ページのコード ビハインドで値を割り当てるだけです。

于 2013-04-22T15:10:54.077 に答える