简体   繁体   English

是否可以使用Xaml设计器或智能感知与Xamarin.Forms?

[英]Is it possible to use a Xaml designer or intellisense with Xamarin.Forms?

Xamarin 3.0 introduced Xamarin.Forms , a powerful UI abstraction that allows developers to easily create user interfaces that can be shared across Android, iOS, and Windows Phone. Xamarin 3.0引入了Xamarin.Forms ,这是一个功能强大的UI抽象,允许开发人员轻松创建可在Android,iOS和Windows Phone之间共享的用户界面。

It seems very powerful but I'm facing a few difficulties to create UI as Xamarin.Forms comes with more than 40 controls. 它似乎非常强大,但我面临一些创建UI的困难,因为Xamarin.Forms带有40多个控件。 Without intellisense or a minimalist designer, it's fairly counter-productive to search for all properties in the official doc or by browsing c# code. 如果没有intellisense或极简主义设计师,搜索官方文档中的所有属性或浏览c#代码会相当适得其反。

The default Xaml teamplate is like this, and it's clearly not trivial to add new controls without any help. 默认的Xaml teamplate就像这样,在没有任何帮助的情况下添加新控件显然不是一件容易的事。

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                       x:Class="App1.Class1">
    <Label Text="{Binding MainText}"  VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>

So is there any chance to have intellisense inside Xaml or to use the Xaml designer ? 那么有没有机会在Xaml中使用intellisense或使用Xaml设计器?

Xamarin.Forms does not come with a graphical designer (yet ?). Xamarin.Forms没有图形设计器(但是?)。 As for intellisense there are 2 parts: intellisense有两部分:

  • referencing xaml element tagged with x:Name in code behind works in both Xamarin.Studio and VisualStudio 引用标记为x XAML元素:代码名称后面均Xamarin.Studio和VisualStudio的作品
  • Xaml completion of elements and attributes works in Xamarin.Studio, and support for completing attributes values is coming very soon. Xaml完成元素和属性在Xamarin.Studio中工作,并且很快就会支持完成属性值。 Unfortunately, intellisense for Xaml in VisualStudio does not work for now. 不幸的是,VisualStudio中的Xaml智能感知现在不起作用。 But the problem is well known, and solutions are investigated. 但问题是众所周知的,并且研​​究了解决方案。

I have had success with Xamarin.Forms Intellisense extension in a PCL but not SAP. 我在PCL中使用Xamarin.Forms Intellisense扩展而不是SAP取得了成功。

在此输入图像描述

Intellisense has been released in its first form, more information here: Intellisense已经以第一种形式发布,更多信息请点击此处:

Mobile Essentials: Productivity Tools for Mobile Developers Mobile Essentials:面向移动开发人员的生产力工具

Xamarin Studio 6.1+ includes a XAML previewer: Xamarin Studio 6.1+包含一个XAML预览器:

在此输入图像描述

It is not perfect, but as a "preview" release does a decent job of rendering your XAML in different resolutions on iOS and Android, including different orientations. 它并不完美,但是作为“预览”版本在iOS和Android上以不同的分辨率呈现您的XAML,包括不同的方向。

A registration required video: https://brax.tv/lesson/xamarin-forms-hello-xaml-previewer/ 需要注册的视频: https//brax.tv/lesson/xamarin-forms-hello-xaml-previewer/

Xamarin Evolve Videos @ https://evolve.xamarin.com Xamarin Evolve Videos @ https://evolve.xamarin.com

(Official Evolve video at the time of this posting are not online yet) (此帖发布时的官方Evolve视频尚未在线)

如果您有Resharper 9,那么intellisense在Visual Studio中工作,具有Clint Landry提到的Xamarin.Forms Intellisense扩展。

A 3rd-Party company is developing a Xamarin.Forms Designer called UI Sleuth. 一家第三方公司正在开发一款名为UI Sleuth的Xamarin.Forms Designer。

They are still in stealth-mode, but have posted a couple of demo videos: 他们仍处于秘密模式,但已发布了几个演示视频:

I recommend following the Lead Architect on Twitter . 我建议在推特上关注首席架构师 This is where they are posting the latest UI Sleuth updates! 这是他们发布最新的UI Sleuth更新的地方!

All that is needed to implement Intellisense on VS is have the Xamarin.Forms XAML schema in a .xsd file placed in the proper folder of visual studio at the installation time. 在VS上实现Intellisense所需的只是在安装时将.xsd文件中的Xamarin.Forms XAML模式放在visual studio的正确文件夹中。 I guess the NuGet package/tasks don't have at the installation time and the access required by the OS(unless you run Visual Studio as Admin and hardcoded paths into NuGet package install tasks, which is not good idea) to do it. 我想NuGet包/任务在安装时没有操作系统所需的访问权限(除非你将Visual Studio作为Admin运行并且硬编码路径运行到NuGet包安装任务中,这不是一个好主意)。

I've throw this same question to Xamarin team and they replied that the Intellisense is yet to come in following updates and the designer in a future(don't know how soon, even for the alpha/beta channels of update). 我已经向Xamarin团队提出了同样的问题,他们回答说Intellisense还有未来的更新和未来的设计师(不知道多久,即使是alpha / beta频道的更新)。

Hope it helps... 希望能帮助到你...

I've just read a tweet about a Xamarin.Forms Designer being announced at Xamarin Evolve 2016 conference 我刚刚在Xamarin Evolve 2016大会上宣布了一条关于Xamarin.Forms Designer的推文

In the mean time you could use the Windows Phone designer and a converter to spit out Xamarin.Forms markup, see: http://www.gui-innovations.com/Blog%20Posts/windows-phones-forms-to-xamarin-forms.html 与此同时,您可以使用Windows Phone设计器和转换器来吐出Xamarin.Forms标记,请参阅: http//www.gui-innovations.com/Blog%20Posts/windows-phones-forms-to-xamarin- forms.html

That tool is also mentioned at together with other related tools at: https://github.com/MvvmCross/MvvmCross-Forms/wiki/XAML-Tools-for-Xamarin 该工具也与其他相关工具一起提及: https//github.com/MvvmCross/MvvmCross-Forms/wiki/XAML-Tools-for-Xamarin

在此输入图像描述

I created two videos that cover how you can use Xamarin Studio's new XAML Previewer: 我创建了两个视频,介绍了如何使用Xamarin Studio的新XAML预览器:

Intro: 介绍:

Using Design Data: 使用设计数据:

Design Data with ViewModelLocator: 使用ViewModelLocator设计数据:

An example of the code involved: 涉及的代码示例:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
        x:Class="STLBrews.Mobile.BreweriesPage"     
        xmlns:vm="clr-namespace:STLBrews.ViewModels;assembly=STLBrews.ViewModels" 
        BindingContext="{x:Static vm:ViewModelLocator.BreweriesVM}">
    <ContentPage.Content>
        <ListView
            ItemsSource="{Binding Items}" >
            <ListView.ItemTemplate> 
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal">
                            <Image Source="{Binding LogoUrl}"/>
                            <StackLayout Orientation="Vertical" Spacing="0" VerticalOptions="Center">
                                <Label Text="{Binding Name}" FontAttributes="Bold"/>
                                <Label Text="{Binding Description}" FontSize="10"/>
                            </StackLayout>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </ContentPage.Content>
</ContentPage>

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

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