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">