0

我正在使用带有 FreshMvvm 框架的 Xamarin 表单。我在 Xaml 中创建页面。我想使用内容视图在多个页面中恢复。

内容视图.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();
        }
    }
}

主页.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>

主页.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 或其程序集之一。

任何人都可以建议,如果我的代码有任何问题。

谢谢。

4

2 回答 2

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">
于 2016-09-27T16:11:45.907 回答
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">
于 2016-09-28T12:37:57.130 回答