如何使用Pages实现MVVM

huangapple go评论112阅读模式
英文:

How to implement MVVM with Pages

问题

我试图在C#中使用MVVM模式与页面。我正在尝试像这样设置DataContext:

  1. public partial class PageView : Page
  2. {
  3. public PageView()
  4. {
  5. BindingContext = new PageViewModel();
  6. //等等
  7. }
  8. }

但BindingContext不存在。

在页面中正确的方法是什么?

英文:

I trying to using the MVVM pattern in c# with Pages. I am trying to set the DataContext like so

  1. public partial class PageView : Page
  2. {
  3. public PageView()
  4. {
  5. BindingContext = new PageViewModel();
  6. //etc

But BindingContext doesn't exist.

What's the correct way to do this for pages?

答案1

得分: 1

DataContext = new PageViewModel();

英文:

It should be

  1. DataContext = new PageViewModel();

huangapple
  • 本文由 发表于 2023年7月13日 22:08:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76680318.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定