简体   繁体   中英

Namespaces in XAML

If I write controls in different namespaces, I can't show the namespaces in XAML. Example:

Namespace Sample -> Class A
Namespace Sample.Controls -> Class B

We can write in XAML:

...
xmlns:sample="clr-namespace:Sample"
xmlns:controls="clr-namespace:Sample.Controls"
...

<sample:A .../>
<controls:B .../>

But this not:

<sample:Controls.B />      <-- Is not correct! ERROR!

But, when we use expresion blend SDK libraries, yes. They can. They have namespaces and are correct. We can use:

<i:Interaction.Behaviors />
<i:Interaction.Triggers />
<i:DependencyObjectHelper.SelfAndAncestors />
...

Write 'i:' and the intelisense show organization in namespaces...

How we can write libraries that do this?

After declaring your name space you have to make an instance of a class from that name space . so use Windows.ressources.

Floww this Link http://www.wpf-tutorial.com/wpf-application/resources/

With the ILSpy i found the answer.

In 'i:interaction' the intellisense show an icon of namespace, but is not a real namespace, is an attached property. Interaction is a static class, and Behaviors and Triggers are attached properties.

Then, when we write:

<TextBox>
    <i:Interaction.Behaviors>     // Is a Attached Property, not an object
         ...
    </i:Interaction.Behaviors>
</TextBox>

I thought that the syntax for properties and attached properties was the same, but no... is , not

<TextBox>
    <TextBox.Width>          // "normal" object property: <object+property>
        ...
    </TextBox.Width>

    <i:Interaction.Triggers> // attached property: <attachedProperty>
        ...
    </i:Interaction.Triggers>
</TextBox>

Is correct?!?

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