0

我使用FreshMvvm框架的Xamarin格式。我正在Xaml中創建頁面。我想要使​​用內容視圖在多個頁面中恢復。Xamarin格式:使用內容視圖問題

ContentView.xaml:

<?xml version="1.0" encoding="UTF-8"?> 
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="Coc.Core.ContentsView"> 
    <ContentView.Content> 
     <StackLayout BackgroundColor="Silver"> 
      <SearchBar Placeholder="Search" BackgroundColor="Olive" /> 
     </StackLayout> 
    </ContentView.Content> 
</ContentView> 

ContentView.xaml,CS:

using System; 
using System.Collections.Generic; 
using Xamarin.Forms; 

namespace Coc.Core 
{ 
    public partial class ContentsView : ContentView 
    { 
     public ContentsView() 
     { 
      InitializeComponent(); 
     } 
    } 
} 

Homepage.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" 
     x:Class="Coc.Core.StartUpPage" 
     xmlns:local="clr-namespace:Coc.Core;assembly=Coc.Core" 
     Title ="Home"> 
    <ContentPage.Content> 
     <StackLayout BackgroundColor="Silver" Spacing="30" Padding ="20,50,20,10" > 
      <Image /> 
      <SearchBar Placeholder="Search" /> 
      <Label Text="Hello" TextColor="Red" Style="{StaticResource infoLabelStyle}"/> 
      <local:ContentsView /> 
     </StackLayout> 
    </ContentPage.Content> 
</ContentPage> 

Homepage.xaml.cs:

using System; 
using System.Collections.Generic; 
using FreshMvvm;c 
using Xamarin.Forms; 

namespace Coc.Core 
{ 
    public partial class StartUpPage : ContentPage 
    { 
     public StartUpPage() 
     { 
      InitializeComponent(); 
     } 

    } 
} 

當我試圖在一個頁面的主頁使用contentsView,我得到一個錯誤:無法加載文件或程序coc.core或其組件的一個。

任何人都可以建議,如果在我的代碼中有任何錯誤。

謝謝。

+0

是 「Coc.Core」 在您的視圖所在的PCL組件的實際名稱? – Jason

+0

是的。它是命名空間 – TheDeveloper

+1

不,不是命名空間。您的項目創建的DLL的實際名稱。在Build - > Output – Jason

回答

1

請變成如下:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:Coc.Core;assembly=Coc.Core" 
    x:Class="Coc.Core.StartUpPage" 
    Title ="Home"> 
1

這可能意味着你的程序集名稱是錯誤的。與其試圖糾正它,你可以忽略它,因爲它似乎是引用當前程序集。

所以你HomePage.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" 
    x:Class="Coc.Core.StartUpPage" 
    xmlns:local="clr-namespace:Coc.Core" 
    Title ="Home">