Closed scottcg closed 2 years ago
When I create an implicit style in Styles.cs
and include that in a Dictionary
that I assign to the application resources, the style does work, e,g,:
Styles.cs
:
public static Style<Label> Labels => labels ??= new (
(LABEL_UI.FontSizeProperty, 30.0)
);
App.xaml.cs
:
window.Resources = Styles.Implicit.Dictionary;
However when I have this in App.xaml
:
<Application.Resources>
<Style TargetType="{x:Type Label}">
<Setter Property="FontSize" Value="50" />
</Style>
</Application.Resources>
and do not assign anything to window.Resources
in App.xaml.cs
, then the implicit style does not work.
Maybe I need to do something in C# to apply implicit styles defined in XAML?
Ok, solved it - not a C# Markup issue: e.g. if you have Dictionary1.xaml
with:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type Label}">
<Setter Property="FontSize" Value="50" />
</Style>
</ResourceDictionary>
and in App.xaml.cs
you do:
public App()
{
this.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("Dictionary1.xaml", UriKind.Relative) });
}
Then it works. Apparently there is a difference between Application.Resources
in App.xaml
and a ResourceDictionary
in a separate xaml
file.
So implicit styles work both from C# and from XAML.
Default styles, such as:
Are not applied to Label() in markup.
In the c# code one can lookup the style and see that it is present using this:
When manually applying this to the Label, it still doesn't work. That may mean there's something strange with how Label deals with Content during construction. Not sure.
You can see this in the Welcome_UI.cs code file.