[英]How to set binding context to another assembly in XAML? Type not found
我是Xamarin / XAML的新手,我正在尝试将它合并到我的项目中,但是当我尝试将BindingContext放入XAML时,我得到“Type not found”错误,但是如果我在C#构造函数中设置它,它就可以工作。 有任何想法吗?
ProjectX.Forms.MainPage.cs
namespace ProjectX.Forms
{
public partial class MainPage
{
public MainPage( )
{
InitializeComponent( );
//this.BindingContext = new ProjectX.ViewModel.MainPage( );
}
}
}
ProjectX.Forms.Mainpage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewModel="clr-namespace:ProjectX.ViewModel;assembly=projectx.viewmodel"
x:Class="ProjectX.Forms.MainPage"
Title="Project">
<ContentPage.BindingContext>
<viewModel:MainPage/>
</ContentPage.BindingContext>
<StackLayout>
<Entry Text="{Binding Input, Mode=TwoWay}"/>
<Label Text="{Binding Output}"
Font="Large"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center">
</Label>
</StackLayout>
</ContentPage>
ProjectX.ViewModel.MainPage.cs
namespace ProjectX.ViewModel
{
public class MainPage : INotifyPropertyChanged
{
...
}
}
按原样,我收到以下错误消息:
Xamarin.Forms.Xaml.XamlParseException: Position 8:6. Type viewModel:MainPage not found in xmlns clr-namespace:ProjectX.ViewModel;assembly=projectx.viewmodel
如果我取消注释ProjectX.Forms.MainPage中的注释并从xaml文件中删除BindingContext内容,则错误消失。
使用XAML而不必将bindingcontext放在构造函数中的最佳方法是什么?
projectx.viewmodel
吗? 您可以在项目属性中检查它。 MainViewModel
的做法)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.