如何更改XAML窗口中多個控件的前景屬性,當不是所有控件都是相同類型?WPF多個控件屬性同時發生變化
我可以在一個堆棧面板中設置TextElement.Foreground
,設置TextBoxes等的前景色(見下面的代碼)。但是,這不會改變按鈕,列表框等的前景色。
如何在窗口中設置全部元素的前景色,而無需爲每個單獨元素或類元素設置它?
<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'? –
我不認爲改變窗口前景將改變TextBox的前景,例如... –
@MikeEason與你的建議,結果仍然是上面的代碼相同。對不起,不起作用。 –