简体   繁体   中英

How to add user control in xaml using metro app win8?

I want to use listview as a control so that i can use it in different pages ,

I have created user control named(MyUserControl1) now the problem how i can add in xaml at any palace.

can you suggest me a best way to do it??

Just include the namespace of the user control on the page where you want it, and then use it.

I don't have a machine right now, it will look something like this:

<page>
<page.resources>
<xmlns:localContolrs="using:CustomControls">
</page.resources>
<localControls.MyControl ItemsSource="Model.MyList" />
</page>

Here I assume MyControl is a List control.

this may help you

Within Visual Studio you can define UserControls by going to Project --> Add New Item and selecting User Control. After defining it there you can then add a reference to it in the XAML of the page you want to use it in. You do this by adding a something along the lines of the following to the root tag of your page.

<common:LayoutAwarePage
    ...
    xmlns:CustomControlName="using:CustomControlNamespace"
    ...>

If you want to do it in the same XAML document, I guess you could define the control in the pages resources

<Page.Resources>

    <UserControl x:Name="CustomControl">
       ...
    </UserControl>

</Page.Resources>

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