Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Making Custom Controls Internal to a Custom Control Assembly
7 replies. Latest Post by michael_weed on December 5, 2008.
(0)
michael_...
Member
29 points
38 Posts
12-03-2008 9:55 AM |
Is it possible to make certain custom controls in an assembly internal to that assembly -- where the publicly-scoped controls could use the internally-scoped controls but external users of the assembly could not?
Bigsby
262 points
81 Posts
12-03-2008 1:02 PM |
Yes.
I use that a lot with custom Panels.
12-03-2008 2:07 PM |
Hi Bigsby,
Exactly. But how did you do it? When I mark the desired control classes "internal" I get design-time errors when I go to use one of the publicly-scoped controls in a project. Besides marking the control classes as internal, is there something else I need to do to the style markup in generic.xaml to "hide" these internal controls?
12-03-2008 3:22 PM |
I'll make a working sample tonight and provide it so you can check it out.
Regarding the generic.xaml question, I'll have to check it out but there shouldn't be nothing else to hide once the Controls are modified as internal. One thing I really don't like that closed process of accessing a file called specifically generic.xaml, specifically in the a folder called Themes and adding resources that you can´t access... too blury for my taste.
Never the less... later on I'll provide the sample.
12-03-2008 4:28 PM |
Great!
I agree with you about the requirement of using a resource dictionary with a required name of generic.xaml. Perhaps this will evolve over time.
Thanks again for your help!
12-05-2008 6:58 AM |
Do you have a working example of this you can provide? As I said before, I've tried simply marking the controls I intend to hide as "internal" and this has not worked. I get a design-time error as soon as I try to use any of the publiclly-scoped controls that depend on one of the internal controls. The error only goes away when I mark all of the controls as "public" again.
12-05-2008 11:33 AM |
There you go.
You can get the working sample here
Hope it helps.
What happens is that generic.xaml is just a kind of patch to workaround the fact that ResourceDictionary is not WPF like implemented yet. The consequence of this is that generic.xaml is parsed "outside" the assembly thus not knowing the internal types. So, to use the internal controls and style them, you'll have to workaround in a manner like the one I propose in the sample.
The reason I didn't run into this kind of trouble in my Panel implementation is I was using the panels precisely to make the parsing/constructing of the UI objects faster not using any XAML and setting my own optimized measure and arranging methods. This was, naturally, all done in the code behind.
If you look at the way I'm getting the Style for the PrivateButton type, you'll see the way I'm setting my styles, now-a-days. I use a private static (thus only instanciated in the first object) field and set it in the constructor. One of the advantage of this is that you don't 3 miles of generic.xaml with all the styles in it which is very little workable.
Well. I think this is enough for you to get the picture.
Anything else, just whistle.
Bruno.
12-05-2008 12:04 PM |
Thanks Bruno. I'll start digging into this right away!