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

标签 xaml windows-phone-7 themes

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

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

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>

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

http://www.windowsphonegeek.com/articles/Creating-WP7-Custom-Theme---Complex-Theme
<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="CustomThemeResources.xaml" />
</ResourceDictionary.MergedDictionaries>

它不起作用...所以我下载了示例应用程序,果然,每个想要更改颜色(如背景颜色)的页面都会将其设置在最外层组件上。
<Grid Background="{StaticResource PhoneBackgroundBrush}">
...
</Grid>

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

最佳答案

在当前版本的 WP7 中不可能有一个新的样式来更改默认样式而不通过“x:Key”明确设置它:

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

现在你可以:

  • 仅覆盖您指出的第一篇文章中所述的默认画笔/颜色资源。请注意,所有 WP7 控件都会更改其颜色。另请注意,出于某种原因,默认背景保持不变。这是当前 WP7 版本的一个已知问题,可能会在“Mango”更新中修复。
  • 如果您想拥有任何新的 Style/ControlTemplate,您必须使用您指出的第二篇文章中提到的 "x:Key"/{StaticResource ...} 方法。

  • 最后,如 德里克·莱金 之前提到过:希望这个错误会在 Mango 更新中得到修复!

    关于xaml - 覆盖默认主题 WP7 的自定义主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5658951/

    相关文章:

    c# - 如何让ListBox子项事件不调用父事件?

    c# - 从网页中检索图像 url

    windows-phone-7 - 如何导航到同一页面并让它触发正常的新页面生命周期?

    Android Datepicker 文本颜色更改不起作用

    themes - 如何使用gatsby-plugin-theme-ui调整主体背景颜色

    WPF 不允许我在绑定(bind)路径上放置绑定(bind)——还有其他方法吗?

    c# - System.Windows.SystemParameters.PrimaryScreenWidth 与转换器的 WPF 绑定(bind)

    silverlight - 如何在 Silverlight 中将资源字符串绑定(bind)到 Xaml

    c# - 如何从服务器获取照片并在 Image Control for Wp7 中显示

    asp.net - 在代码中设置 Page.Theme 会使 css 文件链接到两次