当前位置:编程学习 > C#/ASP.NET >>

Wpf中Button怎么读取显示Xaml文件


谢谢各位大侠不吝赐教 WPF XAML Button --------------------编程问答-------------------- 读取显示Xaml文件是什么意思? --------------------编程问答-------------------- wpf的界面文件都是以xmal文件保存,然后想用一个Button读取选定的xaml文件,然后显示相应xaml文件对应的界面 --------------------编程问答--------------------
string xamlFileName = @"c:\test.xaml";
            string xamlContent = string.Empty;
            try
            {
                using (StreamReader sr = new StreamReader(xamlFileName))
                {
                    xamlContent = sr.ReadToEnd();
                }
            }
            catch (Exception e)
            {
              throw e;
            }
            StringReader stringReader = new StringReader(xamlContent);
            XmlReader xmlreader = XmlReader.Create(stringReader);   
            Canvas canvas1 = (Canvas)XamlReader.Load(xmlreader);
            LayoutRoot.Children.Add(canvas1);//LayoutRoot为Grid
--------------------编程问答-------------------- 怎么在Button里显示呢 --------------------编程问答-------------------- Button 里加个Grid就好了,或者其他面板也行。
[yabao=][/yabao]
<Button HorizontalAlignment="Left" Height="299" Margin="10,10,0,0" VerticalAlignment="Top" Width="497">
            <Grid Height="213" Width="441">
                <Button Content="按钮中的按钮"  HorizontalAlignment="Left" Height="60" Margin="10,10,0,0" VerticalAlignment="Top" Width="182" FontSize="18"/>
                <TextBox Text="按钮中的TextBox" HorizontalAlignment="Left" Height="68" Margin="10,119,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="182" FontSize="18"/>
            </Grid>
        </Button>


--------------------编程问答--------------------
引用 5 楼 ADSL9688 的回复:
Button 里加个Grid就好了,或者其他面板也行。
[yabao=][/yabao]
<Button HorizontalAlignment="Left" Height="299" Margin="10,10,0,0" VerticalAlignment="Top" Width="497">
            <Grid Height="213" Width="441">
                <Button Content="按钮中的按钮"  HorizontalAlignment="Left" Height="60" Margin="10,10,0,0" VerticalAlignment="Top" Width="182" FontSize="18"/>
                <TextBox Text="按钮中的TextBox" HorizontalAlignment="Left" Height="68" Margin="10,119,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="182" FontSize="18"/>
            </Grid>
        </Button>

能给一个全点的代码吗,谢谢了 --------------------编程问答--------------------
引用 6 楼 fengzheng22 的回复:
Quote: 引用 5 楼 ADSL9688 的回复:

Button 里加个Grid就好了,或者其他面板也行。
[yabao=][/yabao]
<Button HorizontalAlignment="Left" Height="299" Margin="10,10,0,0" VerticalAlignment="Top" Width="497">
            <Grid Height="213" Width="441">
                <Button Content="按钮中的按钮"  HorizontalAlignment="Left" Height="60" Margin="10,10,0,0" VerticalAlignment="Top" Width="182" FontSize="18"/>
                <TextBox Text="按钮中的TextBox" HorizontalAlignment="Left" Height="68" Margin="10,119,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="182" FontSize="18"/>
            </Grid>
        </Button>

能给一个全点的代码吗,谢谢了


其他都是是自动生成的代码。
把这段代码放到新建的wpf项目<Grid></Grid>里面就可以看到效果了。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,