Reputation: 582
I Have
class Canvas2:Canvas
{
}
class created in the same namespace. i can't use Canvas2 in XAML. how can i make Canvas2 accessable in XAML code? Im a newby.
Upvotes: 0
Views: 125
Reputation: 1795
A quick and dirty answer: Add the following line to your AssemblyInfo.cs
[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "YourNamespace")]
This way you add all classes in your Namespace to the default WPF-XML-Namespace. Then you can use your classes directly without adding an custom xml namespace.
Warning: Even if this works, it is not the recomended way. Especially I would not recommend this for larger projects because it could easily lead to name conflicts.
The correct way is to add a custom XML namespace like nit and AsitK described.
Upvotes: 0
Reputation: 18580
Define the xmlns like xmlns:local="clr-namespace:WpfApplication1"
assuming Canvas2 is define in namespace WpfApplication1.
then you can use Canvas2 as <local:Canvas2 x:Name="MyCanvas"/>
Thanks
Upvotes: 1