assemblies - How to reference WPF style keys defined in a separate assembly in another library -
I have two libraries and one application assembly layout and I'm thinking how I can reference their keys.
- WpfControls.dll - Common reusable controls such as a WPF based NumericUpDown control as well as other basic controls and some styles as well as I reuse Somewhere I want to make. For example, the key of my style is defined as MyButtonStyle .
- SpecializedControls.dll - Our application is specific to those that control such as custom composite controls and user controls in WPF. This is where I would like to refer to the MyButtonStyle style defined in the WpfControls.dll assembly.
- Application.exe - This is the use of defined controls in the assembly SpecializedControls.dll assembly.
I have explained some examples of how to do this with a simple single control library and application assembly, but in my case I have two assemblies and one application then in my case other words In, I do not have App.XML in my second control library where I can use the concept of merge. I am pretty sure that if I want to be able to put MergedDictionaries reference directly into each control XAML file, then to merge all the generic.xmls defined in the WpfControls.dll assembly, but I guess the result is that the number of styles Will be mixed in different places in my special control assembly which does not seem like the best solution to make the case worse For these Dictionaries application. Can be merged with XE, does it start blooping my application on runtime?
Can anyone explain what is the recommended or best way to share such styles?
Update : For a little more testing Afterwards it appears that I'm having trouble referring to a resource defined within Generic.XML. How do the same assembly resource keys work, I think I should also consider ComponentResourceKey as well as doing some more research. If someone has any suggestions or suggestions, please help.
Resource lookup in WPF works in a hierarchy: Top logical trees, then application resources, theme resources And finally system resources.
Theme resources can usually be accessed inherently (even those are defined in the assembly too). It is only relevant to styles, where the target type can be used as the inherent key.
There are two options for what you are trying to do:
-
Use a ComponentResourceKey This is a special Is a resource key that allows resources to be referred from other assemblies. For example, you can define a brush in WpfControls topic dictionary:
& lt; LinearGradientBrush x: key = "{ComponentResourceKey TypeInTargetAssembly = Local: MyClass, RESOURCEID = MyBrush}" & gt; & Lt; GradientStop color = "red" /> & Lt; GradientStop color = "blue" offset = "1" /> & Lt; / LinearGradientBrush & gt;
And then you can see it in SpecializedControls :
& lt; UserControl Background = "{StaticResource {ComponentResourceKey TypeInTargetAssembly = wpfControls: MyClass, ResourceId = MyBrush}}" />
-
MergedDictionaries application resources To import a dictionary in You can do this in the application assembly, and when the applications load, even those who are in control SpecializedControls will be able to use these resources. You will have a problem with the design time experience in this scenario, which you can solve by having SpecializedControls , that is also a reference for the dictionary, keeping a fake App.xaml.
Hope it helps,
Elise.
Comments
Post a Comment