WPF- Why aren't these styles working?
I am trying to set a global style for multiple control derived types by putting this in my app.xaml:
<Style TargetType="{x:Type Control}">
<Setter Property="Background" Value="{Binding BackgroundBrush, Source={x:Static m:Settings.Instance}, UpdateSourceTrigger=PropertyChanged}" />
<Setter Property="Foreground" Value="{Binding ForegroundBrush, Source={x:Static m:Settings.Instance}, UpdateSourceTrigger=PropertyChanged}" />
<Setter Property="BorderBrush" Value="{Binding ForegroundBrush, Source={x:Static m:Settings.Instance}, UpdateSourceTrigger=PropertyChanged}" />
<Setter Property="UseLayoutRounding" Value="True" />
</Style>
<Style TargetType="{x:Type Window}" BasedOn="{Stati开发者_JAVA百科cResource {x:Type Control}}" />
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Control}}" />
Right now the window style only works in the visual studio design window and the button style doesn't work at all. What have I done wrong?
I've found sometimes that BasedOn is rather particular. If you assign a key then it tends to work more often. I'm not sure if the value bindings are causing your issue as i didn't make and external static class to use.
<Grid.Resources>
<Style x:Key="simpleStyle" TargetType="{x:Type Control}">
<Setter Property="Background" Value="Blue" />
<Setter Property="Foreground" Value="Yellow" />
<Setter Property="BorderBrush" Value="CornflowerBlue" />
</Style>
<Style TargetType="{x:Type Control}" BasedOn="{StaticResource simpleStyle}" />
<Style TargetType="{x:Type Window}" BasedOn="{StaticResource simpleStyle}" />
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource simpleStyle}" />
</Grid.Resources>
<Button Height="50" Width="100">
Hello
</Button>
精彩评论