How do I change the foreground property of multiple controls in a XAML window, when not all the controls are the same type?
I can set TextElement.Foreground
in a stackpanel, to set the foreground color of TextBoxes, etc (see code below). However, this will not change the foreground color of Buttons, ListBoxes, etc.
How can I set the foreground color for all elements in a window, without setting it for each individual element or class of elements?
<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>
I think you'd need to style the controls you want to be affected individually - but just once for each - assuming you want all instances of TextBlock / TextBox / Button etc. to be affected.