【问题标题】:Xamarin Forms Multiple Custom Controls Per PageXamarin 每页形成多个自定义控件
【发布时间】:2016-05-13 13:02:17
【问题描述】:

我有一些可以使用的自定义渲染器和控件。但是如何在一个 Xamarin Forms xaml 页面中放置多个自定义控件?

谢谢

【问题讨论】:

  • 您只需要确保加载这些控件所在的命名空间,然后在 XAML 中引用它们。所以假设你将它们加载为 xmlns:Local= 然后你像这样访问它们,。然后如下面的答案所述,您只需将它们放在您希望设置的布局中。在此处查看示例developer.xamarin.com/guides/xamarin-forms/custom-renderer/…

标签: c# xamarin xamarin.forms


【解决方案1】:

将所有内容包装在您想要的任何普通布局中,例如一个 StackLayout。

【讨论】:

    【解决方案2】:

    只需在 xaml 页面的标题中添加自定义控件的命名空间,然后在布局中引用它们。例如,以下代码中的自定义控件位于文件夹 CustomControls 下的 PCL 中。

    <?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:customcontrols="clr-namespace:MyNameSpace.CustomControls;assembly=MyNameSpace"
                 x:Class="MyNameSpace.Views.Page_One"
                 Title="Page One">
    
    <StackLayout x:Name="stackContent" VerticalOptions="Fill"HorizontalOptions="Fill">
    
    <customcontrols:MY_Entry x:Name="entry1" ></customcontrols:MY_Entry>
    
    <customcontrols:MY_Label x:Name="label1" ></customcontrols:MY_Label>
    
    </Stacklayout>
    
    </ContentPage>
    

    【讨论】:

    • 如果我有两个自定义控件并且都位于不同的命名空间中怎么办?
    • 在 xmlns 标头中添加两者?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 2016-09-19
    • 2020-05-11
    • 1970-01-01
    • 2018-10-21
    • 2012-06-20
    • 1970-01-01
    相关资源
    最近更新 更多