【发布时间】:2015-06-08 14:29:05
【问题描述】:
当不是所有控件都属于同一类型时,如何更改 XAML 窗口中多个控件的前景属性?
我可以在堆栈面板中设置TextElement.Foreground,设置文本框的前景色等(参见下面的代码)。但是,这不会改变 Button、ListBox 等的前景色。
如何为窗口中的所有元素设置前景色,而不为每个单独的元素或元素类设置前景色?
<Window x:Class="XAMLViewTests.AnimationsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AnimationsWindow" Height="300" Width="300">
<StackPanel TextElement.Foreground="Blue">
<ToolBarTray>
<ToolBar>
<TextBlock>Test Tray 1</TextBlock>
</ToolBar>
<ToolBar>
<TextBlock>Test Tray 2</TextBlock>
</ToolBar>
<ToolBar>
<Button>Test Tray 3</Button>
</ToolBar>
</ToolBarTray>
<TextBlock>Test TextBlock</TextBlock>
<Button>Test Button</Button>
<ListBox>ListBox 1
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 2</ListBoxItem>
</ListBox>
</StackPanel>
</Window>
【问题讨论】:
-
如何设置
Window的Foreground? -
我不认为改变Window Foreground会改变TextBox前景,例如...
-
@MikeEason 根据您的建议,结果仍然与上面的代码相同。抱歉,不起作用。