WPF中的app.xaml有什么用处,如何使用?

WPF中的app.xaml有什么用处,如何使用?,第1张

app.xaml就是起始页等一堆参数的配置,相当于控制台程序的Main,是整个程序的入口;比如:

<Application x:Class="ViewControl.App"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

StartupUri="MainWindow.xaml">

<Application.Resources>

</Application.Resources>

</Application>

这个里面的StartupUri就是设置起始页的

加载效果图

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可以覆盖保存文件,不会重复而报错。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11566500.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存