Problem with Resource Dictionaty
-
יום שישי 13 יולי 2012 06:56
1. I have main application and it contains
App.xaml
2. I have another assembly with styles
TextBox.xaml
Shared.xaml
...
If I add following lines to the App.xaml
<ResourceDictionary Source="pack://application:,,,/Denya.VideoFrameExplorer.Styles;Component/Dictionaries/Shared.xaml" /> <ResourceDictionary Source="pack://application:,,,/Denya.VideoFrameExplorer.Styles;Component/Dictionaries/Button.xaml" /> <ResourceDictionary Source="pack://application:,,,/Denya.VideoFrameExplorer.Styles;Component/Dictionaries/Fonts.xaml" /> <ResourceDictionary Source="pack://application:,,,/Denya.VideoFrameExplorer.Styles;Component/Dictionaries/TextBox.xaml" /> <ResourceDictionary Source="pack://application:,,,/Denya.VideoFrameExplorer.Styles;Component/Dictionaries/Label.xaml" /> <ResourceDictionary Source="pack://application:,,,/Denya.VideoFrameExplorer.Styles;Component/Dictionaries/Separator.xaml" />I see my styles and use it.
But I want to isolate this dictionary in the style assembly. Because this style assembly is using by another projects.
So
1. I added DefaultStyle.xaml to the style assembly with lines of code as I wrote before
2. And then I added to the App.xaml only
<ResourceDictionary Source="/Denya.VideoFrameExplorer.Styles;Component/DefaultStyle.xaml" />
And I have problem that for example textBox which defined as
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Shared.xaml" /> <ResourceDictionary Source="Fonts.xaml" /> </ResourceDictionary.MergedDictionaries> <Style TargetType="{x:Type TextBox}"> <Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}" /> <Setter Property="Foreground" Value="#ff353535" /> <Setter Property="FontSize" Value="9pt" /> <Setter Property="BorderBrush" Value="#ff9f9f9f" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="TextBox"> <Border Name="Bd" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true"> <ScrollViewer Name="PART_ContentHost" Background="{TemplateBinding Background}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="false"> <Setter Property="BorderBrush" Value="#ffe51501" /> <Setter Property="Background" Value="#ffe51501" /> <Setter Property="Foreground" Value="White"/> <!--<Setter Value="{StaticResource DisabledForegroundBrush}" Property="Foreground" />--> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>
Is not visible. Why ???
Video Frame Explorerallows you to make thumbnails (caps, previews) of video files My .NET Extras. Coming soon : MVVM Dialog Service, EmptyIfNull ( LINQ ), CombineAsPath, Easy File Size Info
כל התגובות
-
יום שישי 13 יולי 2012 12:24
Well there are two possible reasons for failure
1) The style is bad
2) There is no good reference to the dictionary.
To check the sytling, just copy it over to a Text UserControl put it in the UserControl.Resources section as a style. Add a button and point to that style. Does it work?
3) A Bad reference will usually show up in the output window of the project. Run the project and take a look at the output window. Do you see any errors?
JP Cowboy Coders Unite!
-
שבת 14 יולי 2012 06:43
I have checked and everything is fine.
So I am going to make a small prototype of what I have done.
And if propeblem still relevant in it I uploaded it and ask you a help again.
My intuition tells me that some thing wrong with WPF.
I mean that if we include dictionary in which included dictionary it doesnt' included
Video Frame Explorer allows you to make thumbnails (caps, previews) of video files My .NET Extras. Coming soon : MVVM Dialog Service, EmptyIfNull ( LINQ ), CombineAsPath, Easy File Size Info
- נערך על-ידי SmartWhy שבת 14 יולי 2012 06:43
-
יום שלישי 17 יולי 2012 07:57מנחה דיון
Hi SmartWhy,
I am agree with Javeman, you could check if you have added the reference, and then check if the Path is correct, if both are correct, i think your resource could work as you want, additional, there is a custom has same concern with yours, you could refer to this discusstion:
http://stackoverflow.com/questions/338056/wpf-resource-dictionary-in-a-separate-assembly
Best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
יום חמישי 26 יולי 2012 10:43
So now I'm sure that all I done is correct.
I create a small application that emulate the situation.
It contains a style for label in separate assembly.
And when I link this file exactly everything is work.
<ResourceDictionary Source="pack://application:,,,/Library;component/Styles/Label.xaml"/>
But when I link "common resource" file. Which include the same string it not visible
<ResourceDictionary Source="pack://application:,,,/Library;component/Styles.xaml"/> ... <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/Library;component/Styles/Label.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary>You can download my sample from here StyleAssemblyError
Label Style :
<Style x:Key="{x:Type Label}" TargetType="Label"> <Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="VerticalContentAlignment" Value="Top" /> <Setter Property="FontSize" Value="10pt"/> <Setter Property="Foreground" Value="Red"/> </Style>
Video Frame Explorer allows you to make thumbnails (caps, previews) of video files
My .NET Extras. Coming soon : MVVM Dialog Service, EmptyIfNull ( LINQ ), CombineAsPath, Easy File Size Info
- נערך על-ידי SmartWhy יום חמישי 26 יולי 2012 10:46