如何在Winui 2.x中更改鼠标悬停时的ExpanderHeader背景颜色?
改变背景的方法之一是覆盖StaticResource
<StaticResource
x:Key="ExpanderHeaderBackground"
ResourceKey="CardBackgroundFillColorDefaultBrush" />
悬停时从代码更改不会给予任何结果:
private void Expander_PointerEntered(object sender, PointerRoutedEventArgs e)
{
var expander = sender as Expander;
expander.Resources["ExpanderHeaderBackground"] = Application.Current.Resources["ApplicationPageBackgroundThemeBrush"];
}
private void Expander_PointerExited(object sender, PointerRoutedEventArgs e)
{
var expander = sender as Expander;
expander.Resources["ExpanderHeaderBackground"] = Application.Current.Resources["CardBackgroundFillColorDefaultBrush"];
}
我不想为这个控件重新创建整个样式,只是为了改变标题背景。
Expander源代码:https://github.com/microsoft/microsoft-ui-xaml/blob/release/2.8/dev/Expander/Expander.xaml
1条答案
按热度按时间zrfyljdw1#
您可以直接在可视化树中设置
ToggleButton
元素的Background
属性: