如何在代码中访问 generic.xaml 样式 [英] How to access generic.xaml styles in code

查看:29
本文介绍了如何在代码中访问 generic.xaml 样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直认为 generic.xaml 样式会合并到 Application.Current.Resources 中,但事实并非如此.

I always thought that the generic.xaml styles are merged into the Application.Current.Resources, but they aren't.

generic.xaml 样式存储在哪里?

Where are the generic.xaml styles stored?

如何在代码中访问它们?(不是xaml)

How are they accessable in code? (not xaml)

更新:我知道在 ResourceDictionary 中访问显式或隐式样式的通用 c# 语法.此问题仅与模板化控件的/Themes/Generic.xaml 样式有关.

UPDATE: I know the general c# syntax to access explicit or implicit styles in a ResourceDictionary. This question is only about the styles of the /Themes/Generic.xaml for templated controls.

推荐答案

您无法直接从 (Program Files)\Windows Kits\10\ DesignTime\CommonConfiguration\Neutral\UAP\\Generic 文件夹,它们不会复制到您的应用程序中,因此它们不是您应用程序的一部分,并且您的应用程序不能直接将 generic.xaml 中的资源用作通用资源字典.

You can not access the resource in generic.xaml in your app directly from the (Program Files)\Windows Kits\10\ DesignTime\CommonConfiguration\Neutral\UAP\\Generic folder, they aren't copied into your apps so they are not part of your app and your app can not use the resource in the generic.xaml directly as the general resource dictionaries.

Windows 运行时不使用这些物理文件(包括 generic.xaml)进行运行时查找.这就是为什么它们专门位于 DesignTime 文件夹中,并且默认情况下不会复制到应用程序中的原因.相反,这些资源字典作为 Windows 运行时本身的一部分存在于内存中,并且您的应用对主题资源(或系统资源)的 XAML 资源引用在运行时在那里解析.请参阅 资源字典结构中的主题资源部分.

The Windows Runtime doesn't use these physical files(including the generic.xaml) for runtime lookup. That's why they are specifically in a DesignTime folder, and they aren't copied into apps by default. Instead, these resource dictionaries exist in memory as part of the Windows Runtime itself, and your app's XAML resource references to theme resources (or system resources) resolve there at runtime. See the Theme resources in the resource dictionary structure part.

所以如果你想使用 generic.xaml 中的资源.您应该将其添加为应用程序中的常规 ResourceDictionary,然后您可以从 Page.ResourcesApplication.Current.Resources 访问它.

So if you want to use the resource in the generic.xaml. You should add it as a general ResourceDictionary in your app then you can access it from Page.Resources or Application.Current.Resources.

这篇关于如何在代码中访问 generic.xaml 样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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