Reputation:
I've been working on this for a while and hit a hump that I cannot solve.
The custom style I have works for some elements and not others. For instance, it works for the fonts, and will even format the button fonts, when I've only stipulated the TextBlock fonts.
Most of the other settings it will ignore, eg, panel, stackpanel. In desperation I set both stackpanel and panel and for the NavigationWindow and Pages. I've tried changing the settings to many different elements to test it.
Also, some of the code completion will show options for some of these and others will not. This seems to be independent of what is being rendered and what is not.
I suspect I am missing an import. Any help is appreciated.
APP XAML
<Application x:Class="My.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml">
<Application.Resources>
<Style x:Key="MyWindowStyle">
<Setter Property="Panel.Background" Value="Chocolate" />
<Setter Property="StackPanel.Background" Value="Chocolate" />
<Setter Property="StackPanel.HorizontalAlignment" Value="Stretch" />
<Setter Property="TextBlock.FontWeight" Value="Bold" />
<Setter Property="TextBlock.FontSize" Value="20" />
<Setter Property="Button.Background" Value="White" /> .. ETC
PAGE XAML
<Page x:Class="My.HomePage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" Style="{StaticResource MyWindowStyle}"
mc:Ignorable="d" Title="HomePage">
MAINWINDOW XAML
<NavigationWindow x:Class="My.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="My App" Height="Auto" Source="HomePage.xaml"
Style="{StaticResource MyWindowStyle}" WindowState="Maximized"></NavigationWindow>
Upvotes: 0
Views: 36
Reputation: 16101
I think the problem is caused by mixing styles for different UI elements. You should define separate Styles for TextBox
es, StackPanel
s etc by using the TargetType=
attribute in your style.
Moreover, setting a style for a Window
(no experience with Page
) often does not work in my experience. I revert to setting its properties on the Window
itself.
Upvotes: 2