2015-05-20 83 views
1

使用控制我Xamarin創建自己的自定義渲染器,看起來像這樣:XamarinForms:從自定義呈現在XAML

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」命名空間的有效控制。有任何想法嗎?

回答

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

似乎組件分配與 '=' 操作,而不是 ':' 之一。班級保持不變,現在一切正常。

0

嘗試改變<x:local="clr-namespace:TestApp;assembly:TestApp"><xmlns:local="clr-namespace:TestApp;assembly:TestApp">

而且<x:local:CustomEntry><local:CustomEntry>

+0

完成它,但我得到一個錯誤,說「System.ArgumentNullException:參數不能爲null參數名稱:AssemblyName」。仍試圖找出原因。更新我的代碼示例 –