I am trying to define a global button style in App.xaml and it basically works as I expect. However, I just can't figure out how to make Foreground work correctly. No matter what I do, I get the default text block style (which sets the color to white).
<Style TargetType="{x:Type Button}"> <Setter Property="Margin" Value="3, 5" /> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}" /> <Setter Property="Foreground" Value="Red" /> <Setter Property="Padding" Value="5" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid x:Name="gridMainButton" RenderTransformOrigin="0.5, 0.5"> <Grid.RenderTransform> <ScaleTransform x:Name="scaleTransform" CenterX="0.5" CenterY="0.5" /> </Grid.RenderTransform> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates" > <VisualState x:Name="Normal" /> <VisualState x:Name="MouseOver" /> <VisualState x:Name="Pressed"> <Storyboard> <DoubleAnimation Storyboard.TargetName="scaleTransform" Storyboard.TargetProperty="ScaleX" Duration="0" To="0.85" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Ellipse x:Name="ellipse" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" StrokeThickness="2" Stroke="{StaticResource standardBackground}" Fill="{StaticResource standardBackground}" /> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Margin="4, 8"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
I suppose I could change ContentPresenter to TextBlock, which would be good for this particular application, but I'm looking for a more general solution.
Thanks,
Wts
source share