Skip to main content

Microsoft Silverlight

Answered Question Custom Controls namespace confusion!RSS Feed

(0)

rmcsharry
rmcsharry

Member

Member

345 points

239 Posts

Custom Controls namespace confusion!

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


   

--------------------------------------
If you can meet with triumph and disaster and treat those two imposters just the same...then you'll be a coder my son.

coughlinj
coughlinj

Member

Member

334 points

114 Posts

Answered Question

Re: Custom Controls namespace confusion!

 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.

 

 

rmcsharry
rmcsharry

Member

Member

345 points

239 Posts

Re: Custom Controls namespace confusion!

Yes it does, thanks very much for the quick reply.

 

R.

--------------------------------------
If you can meet with triumph and disaster and treat those two imposters just the same...then you'll be a coder my son.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities