覆盖默认主题的自定义主题 WP7

发布于 2024-11-01 04:46:34 字数 1615 浏览 1 评论 0原文

是否可以创建自定义主题并将其用作默认主题?

我在任何地方找到的每个示例都表明,您可以通过复制 ThemeResources.xamlSystem.Windows.xaml 文件并将它们作为合并字典包含在您的应用中来创建自定义主题。

http://windowsphonegeek.com/articles/Creating- WP7-自定义主题-ndash-基本主题-实现 覆盖 Windows Phone 7 中的主题

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/CustomThemeResources.xaml" />
            <ResourceDictionary Source="Resources/CustomThemeStyles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

然后我阅读了您需要的更多内容将画笔包含在样式文件中,因此在 CustomThemeStyles.xaml 中我有这个。

http://www.windowsphonegeek.com/articles/创建 WP7-自定义主题---复杂主题

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="CustomThemeResources.xaml" />
</ResourceDictionary.MergedDictionaries>

它不起作用...所以我下载了示例应用程序,果然,每个页面都想要更改一些颜色,例如背景颜色,将其设置在其最外层的组件上。

<Grid Background="{StaticResource PhoneBackgroundBrush}">
...
</Grid>

是否可以包含更改所有默认设置的样式/画笔/颜色/等的自定义主题,而不必在任何地方显式设置它们?

Is it possible to create a custom theme and have it used as the default theme?

Every example I can find anywhere says you can create custom themes by copying the ThemeResources.xaml and System.Windows.xaml files and including them as merged dictionaries in your app.

http://windowsphonegeek.com/articles/Creating-WP7-Custom-Theme-ndash-Basic-Theme-Implementation
Overriding themes in Windows Phone 7

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/CustomThemeResources.xaml" />
            <ResourceDictionary Source="Resources/CustomThemeStyles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Then I've read some more that you need to include the brushes inside the styles file, so in CustomThemeStyles.xaml I have this.

http://www.windowsphonegeek.com/articles/Creating-WP7-Custom-Theme---Complex-Theme

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="CustomThemeResources.xaml" />
</ResourceDictionary.MergedDictionaries>

It doesn't work... so I download the sample app and sure enough, every page that wants to have some color changed, like the background color, will set it on it's outer most component.

<Grid Background="{StaticResource PhoneBackgroundBrush}">
...
</Grid>

Is it possible to include custom themes that change the style/brushes/colors/etc of all the defaults without having to explicitly set them everywhere?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谁许谁一生繁华 2024-11-08 04:46:34

在当前版本的 WP7 中,不可能有一种新样式可以在不通过“x:Key”显式设置的情况下更改默认样式:

隐式样式是 Silverlight 4(和 WPF)的一项功能:Windows Phone 7基于 Silverlight 3+(添加了一些 Silverlight 4 功能)。由于 Silverlight 3 中没有隐式样式,这意味着也无法在 Windows Phone 7 中使用它们。

现在您可以:

  1. 仅覆盖默认画笔/颜色资源,如第一个部分中所述您指出的文章。请注意,所有 WP7 控件都会更改其颜色。另请注意,由于某种原因,默认背景保持不变。这是 WP7 当前版本的一个已知问题,可能会在“Mango”更新中修复。

  2. 您想要任何新的 Style/ControlTemplate,则必须使用您指出的第二篇文章中提到的“x:Key”/{StaticResource ...} 方法。

最后,正如 Derek Lakin 之前提到的:希望这个错误能够在 Mango 更新中得到修复!

It is not possible in the current version of WP7 to have a new Style that changes the default one without explicitly set it via "x:Key":

Implicit Styles are a feature of Silverlight 4 (and WPF): Windows Phone 7 is based on Silverlight 3+(with a few Silverlight 4 features added). Since there’s no Implicit Styles in Silverlight 3 this mean that there is no way to use them in Windows Phone 7 as well.

For now you can:

  1. Only override the default Brushes/Colors resources as explained in the first article that you pointed out. Note that all WP7 controls will change their colors. Note also that for some reason the default Background remains unchanged. This is a known issue with the current version of WP7 and probably will be fixed in the "Mango" update.

  2. If you want to have any new Style/ControlTemplate you must use the "x:Key"/{StaticResource ...} approach as mentioned in the second article that you pointed out.

Finally, as Derek Lakin mentioned previously: hopefully this bug will get fixed in the Mango update!

伴我老 2024-11-08 04:46:34

如果您创建一个资源字典并将其命名为包含所有标准画笔资源的 Reset.xaml 之类的名称。将任何自定义资源样式/画笔放入另一个资源字典中(我们现在将其称为 Custom.xaml)。在 App.xaml 中包含这两个资源字典,如下所示:

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Reset.xaml"/>
                <ResourceDictionary Source="Resources/Custom.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary> 
    </Application.Resources>

理论上,这应该足够了,但不幸的是还不够。由于某种原因(希望在 Mango 更新中修复这个错误),您还需要在 Custom.xaml 中包含 Reset.xaml,如下所示:

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Reset.xaml"/>
    </ResourceDictionary.MergedDictionaries>

一旦完成此操作,就应该是这样;你不需要做任何其他事情。

If you create a resource dictionary and call it something like Reset.xaml that contains all of the standard brush resources. Put any custom resource styles/brushes into another resource dictionary (we'll call it Custom.xaml for now). In App.xaml include both of these resource dictionaries as shown here:

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Reset.xaml"/>
                <ResourceDictionary Source="Resources/Custom.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary> 
    </Application.Resources>

In theory, this should be enough, but unfortunately it's not. For some reason (hopefully a bug that will get fixed in the Mango update) you also need to include the Reset.xaml in the Custom.xaml like this:

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Reset.xaml"/>
    </ResourceDictionary.MergedDictionaries>

Once you've done this, that should be it; you shouldn't need to do anything else.

柠檬色的秋千 2024-11-08 04:46:34

随着 Windows Phone Mango (7.1) 的发布,合并 XAML 字典样式的功能不再起作用。目前,您必须在代码隐藏中更改应用程序资源画笔颜色条目;最好在 App.xaml.cs 中 App() 的构造函数中。

示例:

            (App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color = Color.FromArgb(12, 12, 54, 145);
            (App.Current.Resources["PhoneForegroundBrush"] as SolidColorBrush).Color = Colors.Green;
            (App.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush).Color = Colors.Purple;

希望在 WP8 SDK 中我们将不再需要执行此解决方法。

With the release of Windows Phone Mango (7.1), the feature of merging XAML dictionary styles no longer works. Currently, you will have to change the application resource Brush color entry in the code-behind; preferably in constructor of App() in App.xaml.cs.

Example:

            (App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color = Color.FromArgb(12, 12, 54, 145);
            (App.Current.Resources["PhoneForegroundBrush"] as SolidColorBrush).Color = Colors.Green;
            (App.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush).Color = Colors.Purple;

Hopefully in the WP8 SDK we will no longer need to do this workaround.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文