简体   繁体   English

如何在另一个XAML文件中加载XAML文件

[英]How to load a XAML file in another XAML file

I would like to be able to dynamically load a XAML file (or a control belonging to another XAML file, like a grid for example) into a control of the current page. 我希望能够将XAML文件(或属于另一个XAML文件的控件,例如网格)动态加载到当前页面的控件中。 For example and schematically: 例如并示意性地:

In Page1.xaml: 在Page1.xaml中:

<Grid Name=HelloGrid>
    <TextBlock Text="Hello">
</Grid>

In Page2.xaml: 在Page2.xaml中:

<Grid>
   //part where I load Page1.xaml or just HelloGrid
</Grid>

Thanks for your time, Kevin 谢谢你的时间,凯文

You want to do composite xaml and not loading them. 您想执行composite xaml而不加载它们。 You can try creating a usercontrol for your Page1.xaml that contains given a prefix is defined in your xaml files 您可以尝试创建一个包含给您的Page1.xaml一个用户控件a在你定义的前缀xaml文件

CustomControl.xaml CustomControl.xaml

<Grid Name=HelloGrid>
   <TextBlock Text="Hello">
</Grid>

And on your Page1 and Page2 xaml 并在您的Page1和Page2 xaml上

You can do 你可以做

Page1.xaml 的Page1.xaml

<a:CustomControl/>

and

Page2.xaml Page2.xaml

<Grid>
  <a:CustomControl/>
</Grid>

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

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