Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Trouble with ResourceDictionary (Lazy access?)

$
0
0

Hello,

I'm having trouble with my ResourceDictionary. I have a generic.xaml (Build Action=Page)

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:my="clr-namespace:siemens.CSharp.JobManagement"
                    x:Class="IPIPEResourceDictionary"><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="/siemens.CSharp;component/themes/buttons.xaml"/><ResourceDictionary Source="/siemens.CSharp;component/themes/colors.xaml"/><ResourceDictionary Source="/siemens.CSharp;component/themes/controls.xaml"/></ResourceDictionary.MergedDictionaries><Color x:Key="TEST">#25254E</Color></ResourceDictionary>

all other ResourceDictionaries are set to Build Action=Content.

The AssemblyInfo.cs has following entry

[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]

In one of the resource dictionaries I have a Style

<Style TargetType="{x:Type my:IPIPEStatusSideBarView}"><Setter Property="Height" Value="150"/><Setter Property="Width" Value="350"/><Setter Property="Margin" Value="350,0,0,0"/><Setter Property="Background" Value="#65658E"/>

and I have a control that overrides the style key:

public class IPIPEStatusSideBarView : UserControl
	{
		static IPIPEStatusSideBarView()
		{
			DefaultStyleKeyProperty.OverrideMetadata(typeof(IPIPEStatusSideBarView), new FrameworkPropertyMetadata(typeof(IPIPEStatusSideBarView)));

			//GetDefaultStyle()));
		}

The problem is, that the style never gets applied. I have done some testing a found an interesting thing:

var foo = new Uri("Themes/generic.xaml", UriKind.RelativeOrAbsolute);
			ResourceDictionary dict = new ResourceDictionary();

			dict.BeginInit();
			dict.Source = foo;
			dict.EndInit();


			Style = dict["TEST"] as Style;
			Style = dict[typeof(IPIPEStatusSideBarView)] as Style;
			Style = dict[typeof(IPIPEStatusSideBarView)] as Style;

If I access "TEST" it gives my the value immediately. If I access IPIPEStatusSideBarView I get the value only the second time. If I put it one level up into the main dictionary, it works immediately.

What could be wrong. Why is it loaded in some lazy way?

Thanks

Martin



msedi


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>