简体   繁体   中英

Namespace path in WPF XAML

I have Content directory in main solution. In content catalog i have two catalogs: ViewModels and Views

In XAML, i have declared:

 xmlns:vm ="clr-namespace:AppName.Content"

now, i want get reference to some class in ViewModel catalog:

 <DataTemplate DataType="{x:Type vm:LaserPathViewModel}">

I know thats wrong because the namespace of LaserPathViewModel is AppName.Content.ViewModels.

But how get this reference without add next one namespace declaration?

You don't. You have to declare that other namespace. One way to do that is by adding another namespace declaration:

xmlns:vm2 ="clr-namespace:AppName.Content.ViewModel"

And then you can use it like this:

<DataTemplate DataType="{x:Type vm2:LaserPathViewModel}">

But there is another way to declare the namespaces. You can use the XmlnsAttribute which allows you to map multiple .NET namespaces to one X(A)ML namespace. You can find some nice explanation here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM