我的ToggleButton
和它的内容有问题。我希望这些信息是足够的,如果你还需要什么,让我知道!
问题
我有一个ToggleButton
,它在Grid
中包含一个FontIcon
和一个TextBlock
:
<ToggleButton Grid.Row="1" HorizontalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<FontIcon Grid.Column="0"
FontSize="20"
Glyph="{StaticResource mdi_handyman}"
FontFamily="{StaticResource MaterialDesignIconsOutlined}"/>
<TextBlock Grid.Column="1" Margin="10,0,0,0" Text="{x:Bind p:Resources.Dashboard_Maintenance}"/>
</Grid>
</ToggleButton>
ToggleButton
中的文本应该始终是白色的,这就是为什么我为ToggleButton
设置了以下资源:
<SolidColorBrush x:Key="ToggleButtonForeground" Color="{ThemeResource WhiteColor}"/>
<SolidColorBrush x:Key="ToggleButtonForegroundDisabled" Color="{ThemeResource WhiteColor}"/>
<SolidColorBrush x:Key="ToggleButtonForegroundPointerOver" Color="{ThemeResource WhiteColor}"/>
<SolidColorBrush x:Key="ToggleButtonForegroundChecked" Color="{ThemeResource RichBlackColor}"/>
<SolidColorBrush x:Key="ToggleButtonForegroundCheckedPointerOver" Color="{ThemeResource RichBlackColor}"/>
<SolidColorBrush x:Key="ToggleButtonForegroundPressed" Color="{ThemeResource WhiteColor}"/>
<SolidColorBrush x:Key="ToggleButtonBackground" Color="{ThemeResource RichBlackColor}"/>
<SolidColorBrush x:Key="ToggleButtonBackgroundDisabled" Color="{ThemeResource RichBlackColor}"/>
<SolidColorBrush x:Key="ToggleButtonBackgroundPointerOver" Color="{ThemeResource LightPrussianBlueColor}"/>
<SolidColorBrush x:Key="ToggleButtonBackgroundChecked" Color="{ThemeResource VividSkyBlueColor}"/>
<SolidColorBrush x:Key="ToggleButtonBackgroundCheckedDisabled" Color="{ThemeResource PaleVividSkyBlueColor}"/>
<SolidColorBrush x:Key="ToggleButtonBackgroundCheckedPointerOver" Color="{ThemeResource VividSkyBlueColor}"/>
<SolidColorBrush x:Key="ToggleButtonBackgroundPressed" Color="{ThemeResource LightPrussianBlueColor}"/>
现在需要在Grid
中添加FontIcon
,但是FontIcon
的行为与文本相同(显然,ToggleButton
前台的资源是针对整个内容的)。
但是,FontIcon
在ToggleButton
中需要以下行为:
<SolidColorBrush x:Key="ToggleButtonForeground" Color="{ThemeResource VividSkyBlue}"/>
<SolidColorBrush x:Key="ToggleButtonForegroundDisabled" Color="{ThemeResource VividSkyBlue}"/>
<SolidColorBrush x:Key="ToggleButtonForegroundPointerOver" Color="{ThemeResource VividSkyBlue}"/>
<SolidColorBrush x:Key="ToggleButtonForegroundChecked" Color="{ThemeResource RichBlackColor}"/>
<SolidColorBrush x:Key="ToggleButtonForegroundCheckedPointerOver" Color="{ThemeResource RichBlackColor}"/>
<SolidColorBrush x:Key="ToggleButtonForegroundPressed" Color="{ThemeResource WhiteColor}"/>
我猜
我想我可以用一个FontIcon
前台的转换器来解决这个问题,这个转换器绑定到ToggleButton
的选定状态,但是这个转换器也需要ToggleButton
的禁用状态,这使得这个更完整。因为我认为我可以让这个运行,我认为这可能有点笨拙,不令人满意。
有没有人有办法更优雅地解决这个问题?
提前感谢!
1条答案
按热度按时间n9vozmp41#
您可以使用Microsoft.Xaml.行为.WinUI.托管NuGet包。
这是代码,但我改变了颜色,以检查这是否工作。