积极答复者
win8.1如何动态创建一个page?类似于手动新建一个A.xaml页面一样

问题
答案
-
?????
- 已建议为答案 Jamles HezModerator 2014年6月19日 2:51
- 已标记为答案 Jamles HezModerator 2014年6月20日 8:54
- 已编辑 Shi Xin 2015年7月27日 5:43
全部回复
-
你好,lxdhuainan,
一般不建议这么做,同时我也不确定你是否可以这么做,不过我建议你可以把你想要生成的内容放在一个UserControl中,然后Page中加载对应的UserControl即可。
或者你具体想实现的功能是什么可以告诉我们吗?以便可以帮你想一个比较靠谱的办法:)
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later. -
我可以理解你的意思,你可以通过一些代码生成一个动态的UI,不过我的问题也在于此,你必须要把这些UI以page的方式(或者单独的XAML)显示出来吗?因为如果是UserControl的话,只需要一个xaml页面用来承载即可。
举个例子来说,你有N个布局效果,通过UserControl的方式来预定义,在页面中只需要导入UserControl即可实现你需要的效果。
同时我好像没有看到过单独通过cs代码生成页面的例子。
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later. -
你指的继承用户控件是什么意思?我不是很明白,不过可以嵌套用户控件,比如说我有一个UserControl1和UserControl2,
比如说你可以通过如下的方式来把UserControl2的内容放置到UserControl1中:
<UserControl x:Class="App96.MyUserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App96" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid> <local:MyUserControl2></local:MyUserControl2> </Grid> </UserControl>
h或者通过CS的方式:
public sealed partial class MyUserControl1 : UserControl { public MyUserControl1() { this.InitializeComponent(); MyUserControl2 userControl2 = new MyUserControl2(); } }
--James<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later. -
?????
- 已建议为答案 Jamles HezModerator 2014年6月19日 2:51
- 已标记为答案 Jamles HezModerator 2014年6月20日 8:54
- 已编辑 Shi Xin 2015年7月27日 5:43