我已经找了很长时间了,但仍然没有找到一种方法来为跨平台 Xamarin Forms 创建类似 UserControls 的 WPF。这甚至可以做到吗?我在 Visual Studio 2013 中使用 Xamarin。
最佳答案
这是一个 XAML 示例。只需添加,您就可以拥有任何基本视觉元素。例如。网格、StackLayout、图像等。
<Grid xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Mobile.Control.UserControl">
</Grid>
下面是代码
namespace Mobile.Control
{
public partial class UserControl : Grid
{
public UserControl()
{
InitializeComponent();
}
}
}
要使用它,请转到您的页面并实现命名空间
<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">
然后在页面中
<control:UserControl />
关于c# - 用于跨平台 Xamarin Forms 的用户控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31701449/