如何使用Pages实现MVVM

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

How to implement MVVM with Pages

问题

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

public partial class PageView : Page
{
    public PageView()
    {
        BindingContext = new PageViewModel();

        //等等
    }
}

但BindingContext不存在。

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

英文:

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

    public partial class PageView : Page
    {
        public PageView()
        {
            BindingContext = new PageViewModel();

            //etc

But BindingContext doesn't exist.

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

答案1

得分: 1

DataContext = new PageViewModel();

英文:

It should be

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:

确定