Adding extended components using XAML

  • Thread starter Thread starter K Viltersten
  • Start date Start date
K

K Viltersten

I've designed a class MyButton, extending
Button class. I want to use
<MyButton Name="name">text</MyButton>
instead of
<Button Name="name">text</Button>
but the compiler nags about the class not
being a part of the namespace.

How do i add/set the namespace (Test01) to
be valid for my XAML-setup?
 
In the object "Window" add this parameter:
xmlns:test="clr-namespace:xxx;assembly=yyy"

Change the xxx for the namespace of your control
and yyy with the assembly name, or use
xmlns:zzz="clr-namespace:xxx"
if your control is in the same assembly. After
this you can add your control with this code:
<test:MyButton Name="name">text</test:MyButton>
You can change the prefix "test" for something
else, like "local". The final code looks like
this:
<Window x:Class="WpfApplication1.Window1"
xmlns =
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:test="clr-namespace:xxx">
<test:MyButton Name="name">text</test:MyButton>
</Window>

Ah, thanks!
 
Back
Top