首页 文章

MVVMCross,WPF,XAML“无法解析绑定创建者 - 你初步化了Windows Binding”

提问于
浏览
1

我正在尝试使用具有两个视图和两个视图模型的MVVMCross创建一个简单的WPF应用程序 . 我想要发生的是使用 MvvmCross.BindingEx.Wpf nuget包在初始视图上打开第二个视图的按钮 . 这是我的XAML代码中的第一个标记:

<views:MvxWpfView 
         x:Class="FirstMVVMProject.WPF.Views.FirstView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:views="clr-namespace:Cirrious.MvvmCross.Wpf.Views;assembly=Cirrious.MvvmCross.Wpf"
         xmlns:mvx="clr-namespace:mvx;assembly=Cirrious.MvvmCross.BindingEx.Wpf"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300" >

这是按钮:

<Button Width="50" Height="50" mvx:Bi.nd="Command GoCommand"/>

这是我的viewmodel类:

namespace FirstMVVMProject.Core.ViewModels{
using System.Windows.Input;

using Cirrious.MvvmCross.ViewModels;

public class FirstViewModel : MvxViewModel
{      
        private MvxCommand _goCommand;
        public ICommand GoCommand
        {
            get
            {
                _goCommand = _goCommand ?? new MvxCommand(GoToSecond);
                return _goCommand;
            }
        }

        private void GoToSecond()
        {
            base.ShowViewModel<SecondViewModel>();
        }
}
}

当我尝试运行程序时,我在这个按钮所在的行上得到 XamlParseException ,并且在异常快照的内部异常部分,它说

无法解析绑定创建者 - 您是否已初始化Windows绑定 .

我甚至不知道如何处理这个问题 . 有谁知道可能是什么问题以及我如何解决它?

1 回答

  • 0

    按照斯图尔特的指示,我查看了this document,其中描述了Xaml的西藏和里约 . 我在 Setup.cs 课程中遗漏了这段代码 .

    protected override void InitializeLastChance()
    {
        base.InitializeLastChance();
    
        var builder = new MvxWindowsBindingBuilder();
        builder.DoRegistration();        
    }
    

    粘贴后,一切正常 . 谢谢!

相关问题