简体   繁体   English

用于跨平台Xamarin Forms的UserControl

[英]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.

相关问题 如何在Xamarin Forms跨平台中绑定图像集合 - How to bind collection of images in Xamarin Forms Cross-Platform Xamarin中的跨平台OpenGL渲染 - Cross-platform OpenGL rendering in Xamarin 如何重命名Xamarin跨平台应用程序? - How to rename a Xamarin Cross-Platform App? 使用 __ANDROID__ 在跨平台库中编写的代码不会在 Xamarin forms 应用程序中执行 - Code written in Cross-platform library with __ANDROID__ does not execute in Xamarin forms application 在 Xamarin.Forms 跨平台应用程序中使用 Amazon Cognito 用户池进行身份验证 - Authentication with Amazon Cognito User Pools in Xamarin.Forms Cross-Platform App 创建Xamarin.Forms跨平台应用程序时出现“此项目需要Visual Studio更新才能加载”错误 - “This project requires a Visual Studio update to load” error when creating a Xamarin.Forms Cross-Platform Application 如何从 Xamarin Forms 在 a.xaml 文件中获取跨平台应用程序中的可用屏幕尺寸值? - How to Get The Avaible Screen Size Value In Cross-Platform App From Xamarin Forms in a .xaml File? 创建Xamarin.Forms跨平台应用程序时,“此项目需要加载Visual Studio更新”错误 - “This project requires a Visual Studio update to load” error when creating a Xamarin.Forms Cross-Platform Application iOS App(Xamarin)与iOS XAML App(Xamarin.Forms)与跨平台之间的区别是什么 - What are diffs between iOS App (Xamarin) vs. iOS XAML App (Xamarin.Forms) vs. Cross-Platform Xamarin C#跨平台和特定于平台的绑定 - Xamarin C# Cross-Platform and Platform-Specific Binding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM