gpt4 book ai didi

wpf - 更改WPF项目的启动文件

转载 作者:行者123 更新时间:2023-12-02 20:46:46 25 4
gpt4 key购买 nike

我确信这是一个微不足道的问题,但它是我似乎无法解决的问题之一。

我将 App.xaml 中的启动文件从 StartupUri="MainWindow.xaml" 更改为下面的代码,希望这就是我需要做的一切。

<Application x:Class="MVVMPrototype.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MVVMPrototype.View.MVVMPrototype.xaml">
<Application.Resources>

</Application.Resources>

但是,我收到以下错误,指出我需要将构建属性设置为资源,如下所示。以前它被设置为 Page,这与 MainWindow.xaml 的设置相同。

Resource

完成此操作后,我会收到一个编译器错误,指出当前上下文中不存在 InitializeComponent(); 。我知道发生这种情况的唯一一次是当 .cs 文件和 .xaml 文件之间的类/命名空间不同步时,但事实并非如此。

我看过StartupUri documentation但我还没有发现它有那么有帮助。我确信这是我忽略的愚蠢的事情。是的,我已经清理并构建了该项目几次但没有运气。有谁知道怎么解决吗?

更新:Seva Titov 已经解决了第一部分。但现在我有一个 TargetInvocationException ,其中有一个 System.Security.SecurityException 内部异常,如下图所示(如果难以阅读,请在新选项卡中打开图像):

Security Exception

对此有什么想法吗?

最佳答案

StartupUri 指定相对文件位置,并且您在文件夹 View 中似乎有一个文件 MVVMPrototype.xaml,因此您的代码应如下所示:

<Application x:Class="MVVMPrototype.App" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="View/MVVMPrototype.xaml">

关于wpf - 更改WPF项目的启动文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11833796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com