简体   繁体   English

如何使用Metro App Win8在XAML中添加用户控件?

[英]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 , 我想将listview用作控件,以便可以在其他页面中使用它,

I have created user control named(MyUserControl1) now the problem how i can add in xaml at any palace. 我已经创建了名为(MyUserControl1)的用户控件,现在是我如何在任何宫殿添加xaml的问题。

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. 在这里,我假设MyControl是一个List控件。

this may help you 这可能对您有帮助

Within Visual Studio you can define UserControls by going to Project --> Add New Item and selecting User Control. 在Visual Studio中,您可以通过转到Project-> Add New Item并选择User Control来定义UserControls。 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. 在其中定义完之后,您可以在要使用它的页面的XAML中添加对它的引用。您可以通过在页面的根标记中添加以下内容来实现此目的。

<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 如果要在同一XAML文档中执行此操作,我想您可以在页面资源中定义控件

<Page.Resources>

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

</Page.Resources>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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