为每个项目类型单独的 ResourceDictionary [英] Separate ResourceDictionary for each project type

查看:47
本文介绍了为每个项目类型单独的 ResourceDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的共享项目中创建了一个 ResourceDictionary,没有问题.但是,我的某些样式将非常特别* 用于 Windows Phone 8.1,并且不会在 Windows 8.1 中使用.由于 Windows Phone 项目中没有 App.xaml,如何为 Windows Phone 指定一个 ResourceDictionary?

I've created a ResourceDictionary in my Shared project without problem. However, some of my styles will be very particular* to Windows Phone 8.1 and not used in Windows 8.1. As there's no App.xaml in the Windows Phone project, how do I specify a ResourceDictionary just for Windows Phone?

*除了不同的尺寸和边距外,还大量使用了 PhoneAccentBrush,这在 Windows 应用商店应用中显然是不可用的.

*In addition to different sizes and margins, extensive use of PhoneAccentBrush which is obviously not available on Windows Store Apps.

或者,如果 Shared ResourceDictionary 是首选方法,我该如何使用 PhoneAccentBrush 和其他 WP 专用资源?

Or, if the Shared ResourceDictionary is the preferred method, how do I use PhoneAccentBrush and other WP-only resources?

推荐答案

Windows Phone 的强调色是 可用的跨平台作为{ThemeResource SystemColorControlAccentColor},并引用该链接:

The Windows Phone accent colour is available cross platform as {ThemeResource SystemColorControlAccentColor}, and quoting that link:

这也适用于 Windows 8.1 应用程序,因此可以在通用应用程序中共享 XAML 并仍然利用强调色.但由于 Windows 8.1 上不存在强调色,因此我们得到的颜色将始终是 Blueberry.

This also works in Windows 8.1 apps so that it’s possible to share XAML in universal apps and still take advantage of accent color. But since accent color doesn’t exist on Windows 8.1 the color we get will always be Blueberry.

您可能仍然希望基于资源的颜色构建画笔等,但这些可以进入共享的应用程序资源,例如:

You may still want to build brushes based on that colour for resources, etc. but these can go in the shared application resources, so something like:

<Application
    x:Class="My.Universal.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:My.Universal">
    <Application.Resources>
        <!-- This will always be Blueberry on Windows 8, but will follow the accent colour on Windows Phone 8 -->
        <SolidColorBrush x:Key="AccentBrush" Color="{ThemeResource SystemColorControlAccentColor}"/>
    </Application.Resources>
</Application>

如果您确实希望为不同平台拥有完全不同的资源,您可以将字典与两个项目中同一位置的字典合并 - 共享代码神奇地"同时链接到两个项目

If you did want to have completely different resources for the different platforms, you can merge the dictionary with one from the same location in both projects - the shared code is "magically" linked to both projects simultaneously

这篇关于为每个项目类型单独的 ResourceDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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