c# - 用于跨平台 Xamarin Forms 的用户控件

标签 c# xamarin user-controls cross-platform xamarin.forms

我已经找了很长时间了,但仍然没有找到一种方法来为跨平台 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/

相关文章:

c# - 数据注释标签放在哪里?

java - Xamarin Forms java.exe"退出代码 1 (ProGuard)

ios - 如何从 iOS 模拟器获取 IPA 文件

c# - 获取用户控制 HTML

c# - 在表单中将数据从用户控件 A 传递到用户控件 B

c# - 允许在 .ASCX 控件完成加载之前显示 .ASPX 页面吗?

c# - 将文件字节从 C# 序列化到 SQL Server 并再次返回

c# - 将事件分配给事件处理程序的两种不同类型的区别

c# - 如何在 VS 2010 安装项目之前进行目标系统要求测试 c#

android - 在 tabbedpage 的子页面的 segmentcontrol 内路由滑动操作