我可以在使用 Caliburn.Micro 时将 App.xaml 添加回 Xamarin.Forms 项目吗? [英] Can I add App.xaml back to a Xamarin.Forms project while using Caliburn.Micro?

查看:17
本文介绍了我可以在使用 Caliburn.Micro 时将 App.xaml 添加回 Xamarin.Forms 项目吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Caliburn.Micro Xamarin.Forms 示例(设置和功能都说明了 App.cs 的使用,没有随附的 App.xaml.

The Caliburn.Micro Xamarin.Forms samples (both setup and features illustrate the use of App.cs with no accompanying App.xaml.

我想要一个 App.xaml 文件,这样我就可以将应用级资源添加到 xaml 中,现在应该在 Xamarin.Forms 中.这可能吗?我该怎么做?

I'd like to have an App.xaml file though so I can add in App-level resources into xaml which are now supposed in Xamarin.Forms. Is this possible? How do I do it?

推荐答案

请注意,我此后从未添加过,而且未经测试,但它应该可以像这样工作.

Note, I haven't added one afterwards ever and this is untested, but it should work something like this.

App.xaml 后来被引入到 Xamarin.Forms 包和模板中,可能是由于引入了您所指的应用级资源.但基本上,App.xaml 与任何其他 XAML 文件没有什么不同.

The App.xaml was introduced later into the Xamarin.Forms packages and templates, probably due to the introduction of the app-level resources you are referring to. But basically, the App.xaml isn't different from any other XAML file.

添加一个看起来像这样的新 App.xaml 文件:

Add a new App.xaml file which looks somewhat like this:

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="YourNamespace.YourClass">
    <Application.Resources>
        <!-- Application resource dictionary -->
    </Application.Resources>
</Application>

请注意,您需要在 x:Class="YourNamespace.YourClass" 属性中提供您自己的命名空间.现在在您在此处指定的同一个类中,它应该在您的 App.cs 中,确保该类被标记为 partialInitializeComponent(); 在构造函数中被调用.

Note that you need to supply your own namespace in the x:Class="YourNamespace.YourClass" attribute. Now in the same class that you specify here, which should be in your App.cs, make sure the class is marked as partial and the InitializeComponent(); is called in the constructor.

最后,确保您的 App.xaml 文件被标记为 EmbeddedResource 作为构建操作.

Lastly, make sure that your App.xaml file is marked to be an EmbeddedResource as build action.

事实上,这就是它的全部.

In fact that is everything there is to it.

如果要链接 App.xamlApp.xaml.cs 文件,以便它们在 Visual Studio 中显示为一个节点,请在一个文本编辑器并找到 <Compile Include="App.xaml.cs"/> 节点.将其编辑为:

If you want to link your App.xaml and App.xaml.cs file so that they are shown as one node in Visual Studio, open your csproj file in a text-editor and find the <Compile Include="App.xaml.cs" /> node. Edit this to be:

<Compile Include="App.xaml.cs">
  <DependentUpon>App.xaml</DependentUpon>
</Compile>

虽然这看起来更好,但不是绝对必要的.

While this looks nicer, it's not absolutely necessary.

这篇关于我可以在使用 Caliburn.Micro 时将 App.xaml 添加回 Xamarin.Forms 项目吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆