[英]UserControl for cross-platform Xamarin Forms
I have been looking for a long time now but still haven't found a way to create WPF like UserControls for cross-platform Xamarin Forms. 我一直在寻找很长一段时间但仍未找到为跨平台Xamarin Forms创建类似UserControl的WPF的方法。 Can this even be done? 甚至可以这样做吗? I am using Xamarin with Visual Studio 2013. 我在Visual Studio 2013中使用Xamarin。
Here is a XAML example. 这是一个XAML示例。 Just to add you can have any base visual element. 只是添加你可以有任何基础视觉元素。 Eg a Grid, StackLayout, Image etc. 例如Grid,StackLayout,Image等。
<Grid xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Mobile.Control.UserControl">
</Grid>
Here is the code behind 这是背后的代码
namespace Mobile.Control
{
public partial class UserControl : Grid
{
public UserControl()
{
InitializeComponent();
}
}
}
To use it, go to your page and implement the namespace 要使用它,请转到您的页面并实现命名空间
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:control="clr-namespace:Mobile.Control;assembly=Mobile"
x:Class="Mobile.View.MyPage">
And then in the page 然后在页面中
<control:UserControl />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.