我製作了一個Xamarin Forms應用程序,解決方案名爲RESTTest
,我的共享項目名爲RestApp
。Xamarin - 在xmlns中找不到類型clr-namespace
在我的共享項目中,我有一個名爲ViewModels
文件夾,其中包含一個名爲MainViewModel.cs
我有一個叫MainPage.xaml
頁面其中有一個代碼隱藏稱爲MainPage.xaml.cs
類。在我的XAML我想包括我的ViewModels文件夾是這樣的:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:RestApp"
x:Class="RestApp.MainPage"
xmlns:ViewModels="clr-namespace:RestApp.ViewModels;assembly=RestApp">
但是當我添加像這樣綁定到我的網頁:
<ContentPage.BindingContext>
<ViewModels:MainViewModel />
</ContentPage.BindingContext>
我得到一個未處理的異常:
Type ViewModels:MainViewModel not found in xmlns clr-namespace:RestApp.ViewModels;assembly=RestApp
我錯過了什麼?
Hi Sten,在我的'Androiding'中的'Linking'目前設置爲'None'是正確的,我沒有看到「Do not Link」選項 –
@BarneyCmberss是的,這就是它應該的是。如果它仍然沒有找到它然後在你的主要方法在android應用程序中調用Xamarin.Froms.Init添加'object o = typeof(ViewModels.MainViewModel)'以確保類型可以達到編譯時間 –
I嘗試每個鏈接排列,不幸的是這並沒有解決我的問題 –