Xaml style setter doesn't work #10788
-
Is there something special I need to do to get Styles to work? I have a simple Style: <Grid.Resources>
<Style TargetType="AppBarButton" x:Name="MenuStyle">
<Setter Property="Foreground" Value="White" />
</Style>
</Grid.Resources> Then, in the Grid I have: <AppBarButton Icon="World" Label="Companies" BorderThickness="2" Click="Click_Dashboard" Tag="Companies" /> The Foreground property doesn't get set in any of the AppBarButton. I also tried explicitly specifying a style as a StaticResource, but that doesn't even compile. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you want to change styles you have to options, the first with implicit styles (without Here sample you can experiment with: https://playground.platform.uno/#9c23d023 <ContentControl>
<FrameworkElement.Resources>
<Style TargetType="AppBarButton">
<Setter Property="Foreground" Value="Orange" />
</Style>
<Style TargetType="AppBarButton" x:Key="OtherStyle">
<Setter Property="Foreground" Value="Red" />
</Style>
</FrameworkElement.Resources>
<StackPanel>
<AppBarButton Icon="World" Label="Companies" BorderThickness="2" Tag="Companies" />
<AppBarButton Icon="World" Label="Others" BorderThickness="2" Tag="Companies" Style="{StaticResource OtherStyle}" />
</StackPanel>
</ContentControl> |
Beta Was this translation helpful? Give feedback.
If you want to change styles you have to options, the first with implicit styles (without
x:Name
orx:Key
), the second with explicit style (with anx:Name
orx:Key
). You can have more details in Microsoft's WinUI documentation about styles.Here sample you can experiment with: https://playground.platform.uno/#9c23d023