使用Silverlight 4应用主题

3

我一直在尝试让 Silverlight 4 中的主题功能正常工作。

我已经添加了对 System.Windows.Controls.Theming.Toolkit 和 System.Windows.controls.Theming.ShinyRed 的引用。

然后我做了这样的事情:

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input" xmlns:WebbyDraw="clr-namespace:WebbyDraw" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     x:Class="SilverlightApplication1.MainPage"
    Width="960" Height="700"  mc:Ignorable="d"
    xmlns:shinyRed="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.ShinyRed" >
<shinyRed:ShinyRedTheme>
<Grid x:Name="LayoutRoot2">
....
</Grid>
</shinyRed:ShinyRedTheme>
</UserControl>

但我总是得到相同的主题……没有错误,但也没有任何反应。我还尝试了Silverlight 4工具包中的其他主题,并尝试将其应用于单个控件……仍然没有反应……我做错了什么?我已经阅读了几篇教程,但没有找到答案。


你尝试过在app.xaml中添加资源字典吗? - Refracted Paladin
我尝试将命名空间定义(xmlns:shinyRed =“”)放在app.xaml中...但这就是我需要做的全部吗?那似乎没有起作用。 - Timothy Baldridge
1个回答

0
这是我如何使用主题,我还允许用户更改为他们喜欢的主题 -
您可以将ShinyRed.xaml替换为任何其他样式资源文件以支持多个主题,也可以通过编程方式完成(删除一个资源字典并添加另一个)。
在您的用户控件xmal中。
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
<toolkit:Theme x:Name="ThemeContainer">
 <Grid x:Name="LayoutRoot">
... all other controls in the page
</Grid>

复制所有需要的刷子和字体,创建一个名为ShinyRed.xaml的单一样式文件(您可以简单地按照每个文件中的包含内容将其全部放入一个文件中)

因此,在您的App.xaml中引用这个新创建的xaml文件,然后编译和运行即可!

<Application.Resources>
        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>                
                <ResourceDictionary Source="Assets/ShinyRed.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接