美文网首页
【WPF】wpf加载和保存xaml文件

【WPF】wpf加载和保存xaml文件

作者: UnicornChen | 来源:发表于2019-08-27 11:00 被阅读0次

加载效果图:

public MainWindow(string xamlFile)

        {

            InitializeComponent();

            DependencyObject rootElement;

            using (FileStream fs = new FileStream(xamlFile, FileMode.Open))

            {

                rootElement = (DependencyObject)XamlReader.Load(fs);

            }

            Content = rootElement;

            //查找控件(方法一)

            button1 = (Button) LogicalTreeHelper.FindLogicalNode(rootElement, "button1");

修改app.xaml.cs里的启动项

保存功能:


换成Create可以覆盖保存文件,不会重复而报错。

相关文章

网友评论

      本文标题:【WPF】wpf加载和保存xaml文件

      本文链接:https://www.haomeiwen.com/subject/prisectx.html