Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - "User Control" and Namespaces

 
 
Old 02-07-2007   #1 (permalink)
Horst Klein


 
 

"User Control" and Namespaces

How can I define a Namespace for User Contols?

My System SpecsSystem Spec
Old 02-07-2007   #2 (permalink)
Shawnk


 
 

RE: "User Control" and Namespaces

I still a XAML newbie but I think the following is correct.
Is the following what you are looking for?

The format for namespace definition (in a XAML file) is:

[A] xmlns:custom="clr-namespace:SDKSample;assembly=SDKSampleLibrary"

If you have an external assembly of WPF controls
[1] "My_ctr_lib.dll"
with a custom public button type
[2] "My_button"
and wanted to use the XAML namespace prefix
[3] "Ctr_nsp"
to prefix the custom control references.

The XAML namespace defintion is:

[A] xmlns:Ctr_nsp="clr-namespace:My_control_nsp;assembly=My_ctr_lib"

Or:

xmlns:[3]="clr-namespace:[2];assembly=[1]"

Now that the namespace is visible (in XAML code) you can use it with
(1) Object element syntax and (2) Attribute syntax.

To instantiate the control (now that its defined) you

<Ctr_nsp:My_Button Name="My_button_instance">
Button Label
</Ctr_nsp:My_Button>

Note that if your control namespace is IN the same assembly with your
application then you can omit the "assembly=[1]" portion which would yield.

xmlns:[3]="clr-namespace:[2];"

Or:

[A] xmlns:Ctr_nsp="clr-namespace:My_control_nsp;"

If anyone can find a problem with this please let us know :-)

Shawnk

PS. I haven't done this yet but I need to know this.


"Horst Klein" wrote:

> How can I define a Namespace for User Contols?

My System SpecsSystem Spec
Old 02-07-2007   #3 (permalink)
Shawnk


 
 

RE: "User Control" and Namespaces

As soon as I posted this I noticed an error - the correct answer is:

If you have an external assembly of WPF controls
[1] "My_ctr_lib.dll"
with a CLR (C#,VB,etc) namespace of
[2] "My_control_nsp"
with a custom public button type
[3] "My_button"
and wanted to use the XAML namespace prefix
[4] "Ctr_nsp"
to prefix the custom control references.

The XAML namespace defintion is:

xmlns:Ctr_nsp="clr-namespace:My_control_nsp;assembly=My_ctr_lib"

Or:

xmlns:[4]="clr-namespace:[2];assembly=[1]"

To instantiate the control:

<Ctr_nsp:My_Button Name="My_button_instance">
Button Label
</Ctr_nsp:My_Button>

If your control namespace is IN the same assembly use:

xmlns:[4]="clr-namespace:[2];"

Or:

xmlns:Ctr_nsp="clr-namespace:My_control_nsp;"

Sorry about the mistake in the previous response!

Shawnk



"Shawnk" wrote:

> I still a XAML newbie but I think the following is correct.
> Is the following what you are looking for?
>
> The format for namespace definition (in a XAML file) is:
>
> [A] xmlns:custom="clr-namespace:SDKSample;assembly=SDKSampleLibrary"
>
> If you have an external assembly of WPF controls
> [1] "My_ctr_lib.dll"
> with a custom public button type
> [2] "My_button"
> and wanted to use the XAML namespace prefix
> [3] "Ctr_nsp"
> to prefix the custom control references.
>
> The XAML namespace defintion is:
>
> [A] xmlns:Ctr_nsp="clr-namespace:My_control_nsp;assembly=My_ctr_lib"
>
> Or:
>
> xmlns:[3]="clr-namespace:[2];assembly=[1]"
>
> Now that the namespace is visible (in XAML code) you can use it with
> (1) Object element syntax and (2) Attribute syntax.
>
> To instantiate the control (now that its defined) you
>
> <Ctr_nsp:My_Button Name="My_button_instance">
> Button Label
> </Ctr_nsp:My_Button>
>
> Note that if your control namespace is IN the same assembly with your
> application then you can omit the "assembly=[1]" portion which would yield.
>
> xmlns:[3]="clr-namespace:[2];"
>
> Or:
>
> [A] xmlns:Ctr_nsp="clr-namespace:My_control_nsp;"
>
> If anyone can find a problem with this please let us know :-)
>
> Shawnk
>
> PS. I haven't done this yet but I need to know this.
>
>
> "Horst Klein" wrote:
>
> > How can I define a Namespace for User Contols?

My System SpecsSystem Spec
Old 02-07-2007   #4 (permalink)
Horst Klein


 
 

Re: "User Control" and Namespaces

Hi Shawnk

Thanks not what I wanna do.
See my Attached Solution

There a two controls:
One Custom Control with NameSpace:
Namespace Controls
Public Class MyCustomControl
Inherits System.Windows.Controls.Grid
End Class
End Namespace
And one UserControl
And how can I keep the UserControl in a NameSpace?

Horst




My System SpecsSystem Spec
Old 02-07-2007   #5 (permalink)
Horst Klein


 
 

Re: "User Control" and Namespaces

Hi Shawnk

Thanks to explane these basic things.
But in the future the Designtool MS Expression Blend will handle this
declarations.

Best regards
Horst


My System SpecsSystem Spec
Old 02-07-2007   #6 (permalink)
Shawnk


 
 

Re: "User Control" and Namespaces

Horst,

What language are you using?

"Horst Klein" wrote:

> Hi Shawnk
>
> Thanks not what I wanna do.
> See my Attached Solution
>
> There a two controls:
> One Custom Control with NameSpace:
> Namespace Controls
> Public Class MyCustomControl
> Inherits System.Windows.Controls.Grid
> End Class
> End Namespace
> And one UserControl
> And how can I keep the UserControl in a NameSpace?
>
> Horst
>
>
>

My System SpecsSystem Spec
Old 02-08-2007   #7 (permalink)
Horst Klein


 
 

Re: "User Control" and Namespaces

Framework 3.0 VB.net


My System SpecsSystem Spec
Old 02-08-2007   #8 (permalink)
Patrick Stemmler


 
 

Re: "User Control" and Namespaces

On Wed, 7 Feb 2007 16:19:26 +0100, "Horst Klein"
<horst.klein@vitodata.ch> wrote:

>Hi Shawnk
>
>Thanks not what I wanna do.
>See my Attached Solution
>
>There a two controls:
>One Custom Control with NameSpace:
>Namespace Controls
> Public Class MyCustomControl
> Inherits System.Windows.Controls.Grid
> End Class
>End Namespace
>And one UserControl
>And how can I keep the UserControl in a NameSpace?
>
>Horst
>


My System SpecsSystem Spec
Old 02-08-2007   #9 (permalink)
Patrick Stemmler


 
 

Re: "User Control" and Namespaces

Hi Horst



Try with
<UserControl x:Class="Controls.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
</Grid>
</UserControl>

seems generic.xaml is not matching to the rest of the example so I
commented out this.

I hope this works then
it successfully compiled


see you in coffee room

Patrick





On Wed, 7 Feb 2007 16:19:26 +0100, "Horst Klein"
<horst.klein@vitodata.ch> wrote:

>Hi Shawnk
>
>Thanks not what I wanna do.
>See my Attached Solution
>
>There a two controls:
>One Custom Control with NameSpace:
>Namespace Controls
> Public Class MyCustomControl
> Inherits System.Windows.Controls.Grid
> End Class
>End Namespace
>And one UserControl
>And how can I keep the UserControl in a NameSpace?
>
>Horst
>


My System SpecsSystem Spec
Old 02-08-2007   #10 (permalink)
Patrick Stemmler


 
 

Re: "User Control" and Namespaces

Hi Horst

try this:

<UserControl x:Class="Controls.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>

</Grid>
</UserControl>


But i had to comment out the generic.xaml
seems it is not mtaching to the resr of the example....

Hope it works
on my system it compiled


see you in coffee room

Patrick





On Wed, 7 Feb 2007 16:19:26 +0100, "Horst Klein"
<horst.klein@vitodata.ch> wrote:

>Hi Shawnk
>
>Thanks not what I wanna do.
>See my Attached Solution
>
>There a two controls:
>One Custom Control with NameSpace:
>Namespace Controls
> Public Class MyCustomControl
> Inherits System.Windows.Controls.Grid
> End Class
>End Namespace
>And one UserControl
>And how can I keep the UserControl in a NameSpace?
>
>Horst
>


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Can't access "Network and Sharing Center" nor "User Accounts" Vista General
Solved Can't access "Network and Sharing Center" nor "User Accounts" General Discussion
"User account control - Windows needs your permission to continue" Vista security
Vista not wotking with "My Computer" or "Control Panel", "Screen Saver" Vista General
Aero does not fade, but "blinks" during user account control Vista performance & maintenance


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46