My question is almost the same as Why doesn't style-setting of the window background work?. The answer to that question is "your style targets Window
, but that won't be applied to MainWindow
".
In my case, I have the following style which targets RowDefinition. Elsewhere in my xaml, I have a standard Grid with some Row and Column definitions. The target in Application.Resources
exactly matches my xaml RowDefinition
element, yet the style seems only to apply in the designer, and not at runtime.
I'm running Visual Studio 2012, with Update 4, targeting the .NET Framework 4.5.
App.xaml:
<Application x:Class="MyProj.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<Style TargetType="RowDefinition">
<Setter Property="Height" Value="35" />
</Style>
</Application.Resources>
</Application>
DriverEdit.xaml:
<Window x:Class="MyProj.Windows.DriverEdit"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:p="clr-namespace:MyProj.Properties"
xmlns:Controls="clr-namespace:MyProj.Controls"
WindowStartupLocation="CenterOwner"
Title="{Binding Path=SelectedItem.UniqueName, TargetNullValue='New'}" Height="300" Width="300">
<DockPanel>
<StackPanel DockPanel.Dock="Right">
<Controls:CommonEditButtons />
</StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="{x:Static p:Resources.CommonEditID}" />
<TextBlock Grid.Column="0" Grid.Row="1" Text="{x:Static p:Resources.CommonEditName}" />
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Path=SelectedItem.Id}" />
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding Path=SelectedItem.Name}" />
</Grid>
</DockPanel>
</Window>
Edited to provide more XAML.