0

有没有办法自动将主题/模板/样式应用于目标类型的所有控件,所以我不必在所有控件上指定 Template=..., Style=...?

4

3 回答 3

2

我认为有一种方法可以通过省略 x:Key 属性来做到这一点,但这似乎不再起作用了。根据一些谷歌搜索,在我看来,最好的办法是创建一个自己的自定义控件库,其中包含一个定义自定义样式的主题/generic.xaml 文件。然后,您可以使用自己的样式正确的元素(MyButton 而不是 Button)。要么坚持使用 Style 属性

这里的一些例子和使用主题的替代方法这里

更新:刚刚在这里找到了一个很好的例子(我想你可能已经看过了:)。

于 2008-10-08T18:04:59.507 回答
1

To set up a theme for all controls create a Startup event and set the theme in the Startup event Handler. That theme will be applied all user control in that solution.

//App.xaml

<Application x:Uid="Application_1" x:Class="SampleApp.Home.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml"
             Startup="Application_Startup">

//App.xaml.cs

private void Application_Startup(object sender, StartupEventArgs e)
        {
            StyleManager.ApplicationTheme = new MetroTheme(); //Set your theme here           
        } 
于 2012-02-16T03:50:22.293 回答
0

Einarl:目前还没有办法在 Silverlight 2 核心中“级联”控制模板/样式。也就是说,您不能为 TextBox 设置样式/控件模板,并期望所有 TextBox 都将其选中。这绝对是团队正在为未来版本寻找的东西。

于 2008-10-08T19:02:31.607 回答