简体   繁体   English

如何在Xamarin表单中创建menuitem(?)?

[英]How to create menuitem (?) in Xamarin forms?

I just have a quick question on where i can find documentation about a view like this below that i see on a lot of different for example iOS apps: 我只是有一个快速的问题,我在哪里可以找到有关以下视图的文档,我可以在许多不同的示例(例如iOS应用程序)中看到这些视图:

在此处输入图片说明

Is there a sample project or documentation somewhere on how to implement it in xamarin forms? 是否在某个地方有示例项目或文档,说明如何以xamarin形式实现它? Perhaps this isn't possible but is there a similiar option out there for Xamarin forms development? 也许这是不可能的,但是Xamarin表单开发是否有类似的选择?

This is a segmented control . 这是一个分段控件 There is no default support for it in Xamarin.Forms, probably because it isn't a control that is common on all three platforms. Xamarin.Forms中没有默认支持,这可能是因为这不是在所有三个平台上都通用的控件。

There are a few ways about this if you still want to use it. 如果您仍然想使用它,有几种方法。 Which basically break down to two scenarios: you either use the real native control and have to create different views for iOS and the other platforms you want to use. 基本上可以分为两种情况:要么使用真正的本机控件,要么必须为iOS和要使用的其他平台创建不同的视图。 Or you simulate the segmented control with for instance the FreshEssentials NuGet by Michael Ridland. 或者,您可以使用例如Michael Ridland的FreshEssentials NuGet模拟分段控件。 There are more of them out there. 有更多的人在那里。

If you choose the latter implementation will be easy and can be done right from XAML. 如果选择后者,则实现起来很容易,并且可以直接从XAML完成。

If you choose the first option you can either do it with a custom renderer or with the Native Embedding (Xamarin.Forms 2.2.0+) features. 如果选择第一个选项,则可以使用自定义渲染器或本机嵌入(Xamarin.Forms 2.2.0+)功能来完成。 I have written a blogpost about it, but here are the basics. 我已经写了一篇关于它的博客文章,但是这里是基础知识。 I am assuming you are using XAML to model your interface. 我假设您正在使用XAML对接口进行建模。

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:EmbedNativeAwesomeness"
    xmlns:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS"
    x:Class="EmbedNativeAwesomeness.EmbedNativeAwesomenessPage">

<!-- Rest of page here -->
</ContentPage>

First add the ios namespace declaration to your page. 首先将ios名称空间声明添加到您的页面。 Notice how it has a targetPlatform tag in it, which means this will only be included when the iOS project is targeted. 请注意,它里面有一个targetPlatform标记,这意味着只有在以iOS项目为目标时才会包括在内。

Now, with the ios: prefix you can access all the iOS platform controls directly in Forms, in XAML. 现在,有了ios:前缀,您可以直接在XAML的Forms中访问所有iOS平台控件。

So declaring the Segmented Control would probably be something like: <ios:UISegmentedControl /> and specifying the right properties to your needs. 因此,声明分段控件可能类似于: <ios:UISegmentedControl />并根据需要指定正确的属性。

There are some drawbacks to this method right now, but I'm sure you can work around it. 目前,此方法有一些缺点,但是我敢肯定您可以解决它。 For more info check my blogpost (and accompanying sample code ) or some more resources here . 有关更多信息,请在此处查看我的博客文章(以及随附的示例代码 )或其他资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM