1

I've just begun dabbling in putting together a set of controls as assemblies and I'm working on default styling. What I currently have is a UserControl in a project (thanks Reed!) and I'm able to bring that into another project via reference. I plan to add more controls over time to build something of an SDK.

I currently have some hooks that look for resources in the hosting application which either apply the resources to their respective properties, or style out the control via hard coded defaults.

Is it possible to set up resource dictionaries within the project containing the UserControls so they can use those references as the default, instead of hard coding? If so, how do I target them?

(I have a ResourceDictionary set up within the same project as the controls: Resources>Dictionaries>Colors.xaml)

Thanks in advance!

E

Eric
  • 2,061
  • 8
  • 28
  • 37
  • Okay, thanks to the info you both provided, I've managed to make a bit of headway on this, but now I'm running into a snag and maybe you guys can help. – Eric Oct 21 '10 at 17:11
  • (adding this comment because didn't insert a carriage return - oops!) I have a new project set up using generic.xaml in a Themes folder, and a class file for the first control. When I try to run the project consuming the assembly, I get "Failed to create a 'System.Type' from the text 'local:SolidGloss' - SolidGloss.cs has its namespace set as UXSDK, and in generic.xaml, I am using xmlns:local="clr-namespace:UXSDK; assembly=UXSDK", and in the template, TargetType="local:SolidGloss" am I missing anything? – Eric Oct 21 '10 at 17:15
  • Have you tried the edit function under the tags above, that usually the best way to expand your question rather than adding a comment, which is harder to read. – AnthonyWJones Oct 21 '10 at 22:07
  • I wasn't sure what to do. I am still getting used to this format of Q&A. Thanks for your patience and advice :) – Eric Oct 22 '10 at 16:03

3 Answers3

0

You should really look at creating custom templated controls in library rather than derivatives of UserControls. This will allow projects that reference your library to specify an alternative default style for you controls in the same way as we can for the controls in Microsofts own SDK.

The Creating a New Control by Creating a ControlTemplate topic on MSDN is good starter.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • What I'm trying to do is to eliminate the necessity for multiple files, for portability. The goal is to have a set of controls under one assembly that can be referenced for multiple projects. These controls will have exposed properties to allow styling without generating templates. It's a matter of allowing others in the organization to quickly assemble views that conform to our visual guidelines "out-of-the-box". – Eric Oct 21 '10 at 14:17
0

I think this is a better explanation, but i'm trying on a desktop application and i got the same problem.

XamlParseException: Failed to create a 'System.Type' from the text 'local:CustomerEntity'

Ziad
  • 187
  • 2
  • 3
  • 13
-1

If I'm undestanding correctly you want to create the file "generic.xaml" in the folder "Themes". However, I don't believe automatic styling works with UserControl only with Control. Generally if you trying to make a control that can be stylized and retemplated you want to inherit from Control and not UserControl.

Stephan
  • 5,430
  • 2
  • 23
  • 31