在WPF,C#中,如何将页面内容更改为后面代码中另一页面的内容 [英] In WPF, C#, how to change the content of a page to the content of another page in code behind

查看:242
本文介绍了在WPF,C#中,如何将页面内容更改为后面代码中另一页面的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



有没有办法使用后面的代码将当前页面的内容更改为另一页面的内容。

请注意,当前页面是从主窗口的框架中调用的。



先谢谢

Dear All,

Is there any way to change the content of the current page to the content of another page using code behind.
Please note that the current page is being called from a frame in the mainwindow.

Thanks in Advance

推荐答案

您好,您可以接下来的意思:

Hi , you can achive by next mean:
string xaml =
    "<grid margin="10" hold=" />        " xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">" + 
        "<grid.columndefinitions>" +
            "<columndefinition width="100" />" +
            "<columndefinition width="*" />" +
        "</grid.columndefinitions>" +
 
        "<grid.rowdefinitions>" +
            "<rowdefinition height="Auto" />" +
            "<rowdefinition height="Auto" />" +
            "<rowdefinition height="Auto" />" +
            "<rowdefinition height="*" />" +
        "</grid.rowdefinitions>" +
 
        "<textblock text="First Name" height="19" margin="0,7,31,4" />" +
        "<textbox x:name="FirstName" margin="3" grid.row="0" grid.column="1" />" +
 
        "<textblock text="Last Name" margin="0,7,6,3" grid.row="1" height="20" />" +
        "<textbox x:name="LastName" margin="3" grid.row="1" grid.column="1" />" +
 
        "<textblock text="Date of Birth" grid.row="2" margin="0,9,0,0" height="21" />" +
        "<sdk:datepicker x:name="DateOfBirth" margin="3" grid.row="2" grid.column="1" />" +
 
        "<button x:name="SubmitChanges" grid.row="3" grid.column="3" hold=" />            " horizontalalignment="Right" verticalalignment="Top" margin="3" width="80" height="25" content="Save" />" +
    "</grid>";
 
 
    UIElement tree = (UIElement)XamlReader.Load(xaml);
 
    LayoutRoot.Content=tree;





要读取现有页面的XAML,您可以执行下一步操作:



To read a XAML of existing page you might perform next operation:

StreamResourceInfo sri = Application.GetResourceStream
    (new Uri("SilverlightTestApp;component/Page.xaml", UriKind.Relative));
StreamReader reader = new StreamReader(sri.Stream);
Output.Text = reader.ReadToEnd();





还剩下的最后一件事就是整理这个两段代码并使一个正确=)



And the last thing that still remains for you is to collate this two pieces of code and make one proper =)


这篇关于在WPF,C#中,如何将页面内容更改为后面代码中另一页面的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆