1

我在 Xamarin 中创建了自己的自定义渲染器,如下所示:

namespace TestApp
{
    public class CustomEntry : Entry
    {
        public CustomEntry ()
        {
        }
    }
}

如何将它包含在我的 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" 
xmlns:local="clr-namespace:TestApp;assembly:TestApp" 
x:Class="TestApp.SubPage">
    <ContentPage.Content>
        <StackLayout>
            <local:CustomEntry></local:CustomEntry>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

但它不起作用,说 CustomEntry 不是“ http://xamarin.com/schemas/2014/forms ”命名空间中的有效控件。有任何想法吗?

4

2 回答 2

0

试试<x:local="clr-namespace:TestApp;assembly:TestApp">改成<xmlns:local="clr-namespace:TestApp;assembly:TestApp">

<x:local:CustomEntry>进入<local:CustomEntry>

于 2015-05-20T19:25:50.737 回答
0

没关系,我发现了问题。似乎我的 xmlns:local 声明是错误的。我有这个:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
xmlns:local="clr-namespace:TestApp;assembly:TestApp" 
x:Class="TestApp.SubPage">

就是这样:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
xmlns:local="clr-namespace:TestApp;assembly=TestApp" 
x:Class="TestApp.SubPage">

似乎程序集被分配了“=”运算符,而不是“:”。课程保持不变,现在一切正常。

于 2015-05-20T19:38:56.730 回答