C# Xamarin每页形成多个自定义控件
我有一些自定义的渲染器和控件。但是如何在一个Xamarin Forms xaml页面中放置多个自定义控件呢C# Xamarin每页形成多个自定义控件,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我有一些自定义的渲染器和控件。但是如何在一个Xamarin Forms xaml页面中放置多个自定义控件呢 谢谢将所有内容包装在您想要的任何普通布局中,例如StackLayout。将所有内容包装在您想要的任何普通布局中,例如StackLayout。只需在xaml页面的标题中添加自定义控件的名称空间,然后在布局中引用它们。例如,下面代码中的自定义控件位于文件夹CustomControls下的PCL中 <?xml version="1.0" encoding="utf-8" ?> <
谢谢将所有内容包装在您想要的任何普通布局中,例如StackLayout。将所有内容包装在您想要的任何普通布局中,例如StackLayout。只需在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>
只需在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>
您只需要确保加载这些控件所在的命名空间,然后在XAML中引用它们。假设您将它们作为xmlns:Local=加载,然后像这样访问它们。然后,如下面的回答所述,您只需将它们放在您希望设置的布局中。请参阅这里的示例,您只需要确保加载这些控件所在的名称空间,然后在XAML中引用它们。假设您将它们作为xmlns:Local=加载,然后像这样访问它们。然后,如下面的回答所述,您只需将它们放在您希望设置的布局中。请参阅此处的示例,如果我有两个自定义控件,它们都在不同的名称空间中,该怎么办?将它们都添加到xmlns头中?如果我有两个自定义控件,它们都在不同的名称空间中,该怎么办?将它们都添加到xmlns头中?