【问题标题】:Is it possible to use a Xaml designer or intellisense with Xamarin.Forms?是否可以将 Xaml 设计器或智能感知与 Xamarin.Forms 一起使用?
【发布时间】:2014-07-31 17:12:41
【问题描述】:

Xamarin 3.0 引入了Xamarin.Forms,这是一种强大的 UI 抽象,允许开发人员轻松创建可在 Android、iOS 和 Windows Phone 之间共享的用户界面。

它看起来非常强大,但我在创建 UI 时遇到了一些困难,因为 Xamarin.Forms 带有 40 多个控件。如果没有智能感知或极简设计师,在官方文档中搜索所有属性或通过浏览 c# 代码会适得其反。

默认的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>

那么有没有机会在 Xaml 中使用智能感知或使用 Xaml 设计器?

【问题讨论】:

  • and it's clearly not trivial to add new controls without any help - 我guess 这是针对以前有 XAML 知识的开发人员?我不明白在那里添加控件是“不简单的”。只需修改 XAML 并添加一些容器(它们有多个布局容器)并开始在其中添加控件。
  • 顺便说一句,在里面看到{Binding}真是AWESOMEE​​EEE。这意味着 Xamarin 的 XAML 比我想象的更接近 real XAML。
  • 好的,添加内容就像编辑任何基于 xml 的文件一样简单。我只想说添加新控件并不容易,因为 Xaml 区分大小写并且 Xamarin.Forms 引入了新控件(所以新属性)。这是一套全新的控件。
  • hmm.. 如果您有该命名空间"http://xamarin.com/schemas/2014/forms" 的适当架构 (XSD),至少您应该获得 Visual Studio 的默认 XML 智能感知...您是否尝试过在 VS 的 XML 编辑器中打开文件?
  • @HighCore:XAML 是一种语言。 {Binding} 不是语言的一部分,它是一个标记扩展。样式、模板等...不是 XAML 规范的一部分。这并不意味着它们在 Xamarin.Forms 中不受或不会受支持。这 (msdn.microsoft.com/en-us/library/ms788723(v=vs.110).aspx) 是 xaml,仅此而已。

标签: c# xaml xamarin xamarin.forms


【解决方案1】:

Xamarin.Forms 没有图形设计器(还没有?)。至于智能感知,有两部分:

  • 在 Xamarin.Studio 和 VisualStudio 中 works 后面的代码中引用带有 x:Name 标记的 xaml 元素
  • 元素和属性的 Xaml 补全在 Xamarin.Studio 中工作,并且很快就会支持补全属性值。不幸的是,VisualStudio 中 Xaml 的智能感知目前无法正常工作。但这个问题是众所周知的,并且正在研究解决方案。

【讨论】:

  • @Cyber​​maxs Xamarin Studio 现在有一个 XAML 预览器,看我的回答
  • 你知道 Xamarin.Forms 的 XSD 文件吗?关于这个主题有什么新东西吗?
【解决方案2】:

我在 PCL 中使用 Xamarin.Forms Intellisense 扩展取得了成功,但 SAP 没有。

【讨论】:

  • 我现在也智能感知 PCL 项目中的 Xamarin.Forms xaml 文件。有关安装说明,请参阅此链接cazzulino.com/mobileessentials.html
  • 它工作了一天(我见过的最差的 Xaml 智能感知)。但是当我重新启动 Visual Studio 时,它不再起作用了。
【解决方案3】:

Intellisense 已经发布了它的第一个形式,更多信息在这里:

Mobile Essentials: Productivity Tools for Mobile Developers

【讨论】:

  • 此外,如果您使用 Resharper,它现在为 Xamarin.Forms 实现 Intellisense
  • 是的。这就是我上个月所说的。
  • resharper +1 - 即使它是商业的,考虑到 Visual Studio 的 Xamarin.Forms 价格为 1000 美元/年,如果您还没有拥有它,resharper 的 149 美元/年是一个不错的补充。大多数其他选择都是浪费时间。
【解决方案4】:

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

它并不完美,但作为“预览”版本,在 iOS 和 Android 上以不同的分辨率(包括不同的方向)呈现 XAML 方面做得不错。

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

Xamarin 进化视频@https://evolve.xamarin.com

(发帖时官方的 Evolve 视频尚未上线)

【讨论】:

    【解决方案5】:

    如果您有 Resharper 9,则 intellisense 可以在 Visual Studio 中使用,并使用 Clint Landry 提到的 Xamarin.Forms Intellisense 扩展。

    【讨论】:

      【解决方案6】:

      第 3 方公司正在开发一个名为 UI Sleuth 的 Xamarin.Forms 设计器。

      他们仍处于隐身模式,但发布了几个演示视频:

      我推荐following the Lead Architect on Twitter。这是他们发布最新 UI Sleuth 更新的地方!

      【讨论】:

        【解决方案7】:

        在 VS 上实现 Intellisense 所需要做的就是在安装时将 .xsd 文件中的 Xamarin.Forms XAML 架构放置在 Visual Studio 的正确文件夹中。我猜 NuGet 包/任务在安装时并没有操作系统所需的访问权限(除非您以管理员身份运行 Visual Studio 并将路径硬编码到 NuGet 包安装任务中,这不是一个好主意)。

        我已经向 Xamarin 团队提出了同样的问题,他们回答说 Intellisense 尚未在后续更新和设计器中出现(不知道多快,即使对于更新的 alpha/beta 通道) .

        希望对你有帮助...

        【讨论】:

        【解决方案8】:

        我刚刚阅读了一条关于在 Xamarin Evolve 2016 会议上宣布的 Xamarin.Forms Designer 的推文

        同时,您可以使用 Windows Phone 设计器和转换器来生成 Xamarin.Forms 标记,请参阅: http://www.gui-innovations.com/Blog%20Posts/windows-phones-forms-to-xamarin-forms.html

        该工具还与其他相关工具一起在以下位置被提及: https://github.com/MvvmCross/MvvmCross-Forms/wiki/XAML-Tools-for-Xamarin

        【讨论】:

          【解决方案9】:

          我制作了两个视频,介绍如何使用 Xamarin Studio 的新 XAML 预览器:

          Intro:

          Using Design Data:

          Design Data with ViewModelLocator:

          涉及的代码示例:

          <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>
          

          【讨论】:

            猜你喜欢
            • 2017-06-16
            • 1970-01-01
            • 2015-01-05
            • 1970-01-01
            • 2018-07-18
            • 1970-01-01
            • 2015-01-07
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多