Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Custom Controls namespace confusion!
2 replies. Latest Post by rmcsharry on September 26, 2008.
(0)
rmcsharry
Member
345 points
239 Posts
09-26-2008 4:15 PM |
Hi,
I am having my first go at creating a custom control, but there is one thing I don't get, which is the namespace. I know how to use namespaces and references from my application project and understand them conceptually (well, almost!).
My question is when you create a custom control, in my generic.xaml I have to add a reference, ie:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyCustomControls.Windows.Controls;assembly=MenuBar">
What I want to understand is the meaning/purpose and CONSEQUENCE of the bold writing. I know that the assembly name (MenuBar in this case) creates a MenuBar.dll.
For example:
If I later create another custom control to use in the same project, ideally I want all my custom controls to be in the same namespace, so do I create them all in this generic.xaml or do I create another custom control project with a new generic.xaml and use the same namespace (but a different assembly name?).
So I'm trying to understand the consequence of the namespace for later projects I guess, but also the theory of namespaces in general.
Any info or links to some info would be great, thanks.
Richard
coughlinj
334 points
114 Posts
09-26-2008 4:30 PM |
Richard the namespace referenced in the generic.xaml relates to the namespace of your Custom Controls. A generic.xaml can contain many custom control's with multiple namespace references.
For example in the same Custom Control Library I can declare two different custom controls.
Namespace-> MyControls.namespaceY, Class-> controlA
Namespace-> MyControls.namespaceZ, Class-> controlB
You can then declare the UI for each of these controls in the generic.xaml.
eg.
xmlns:localY="clr-namespace:MyControls.namespaceY;assembly=MenuBar">
xmlns:localZ="clr-namespace:MyControls.namespaceZ;assembly=MenuBar">
and would reference the Styles as "localY:controlA" and "localZ:controlB"
Hope that helps you out.
09-26-2008 9:09 PM |
Yes it does, thanks very much for the quick reply.
R.