I have a single window wpf application and tried setting up a window-wide style to apply to all my TextBox controls. I have another style that is working as expected on the TextBlock controls, but for some reason the TextBox style only work when I use an x:Key. I'm trying to have this style be the global for all TextBox in my window.
I should note that I have tried multiple properties on my TextBox style, including border thickness, foreground, background, TextWeight, etc and nothing works unless it is keyed the style is explicitly defined for each TextBox control.
This block of code is currently in my App.xaml, but I also tested it under the Window.Resources.
<ResourceDictionary>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="clr-namespace:GraphicalNestingCalculator.ViewModel" />
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Blue"/>
</Style>
<Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="Red"/>
</Style>
</ResourceDictionary>
And the TextBox in a stackpanel
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="10,0,10,0"/>
</Style>
</StackPanel.Resources>
<TextBlock>Part Width:</TextBlock>
<TextBox Name="partWidthTextBox" Text="{Binding Path=Layout.Part.Width, UpdateSourceTrigger=LostFocus}" Style="{StaticResource TextBoxStyle}" Width="50" >
</TextBox>
<TextBlock>Part Height:</TextBlock>
<TextBox Name="partHeightTextBox" Text="{Binding Path=Layout.Part.Height, UpdateSourceTrigger=LostFocus}" Style="{StaticResource TextBoxStyle}" Width="50" />
</StackPanel>