wpf 移动 MainWindow.xaml
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25472765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Moving MainWindow.xaml
提问by user3208179
I've built a WPF app, which completely works now. However, to clean it up a bit I wish to move my MainWindow.xamlto the view folder I've created. After I've done this the application won't run and it gives me an "Unknown build error"which doesn't give any info on how to fix it...
What should I change in my MainWindow.xamlto let the app work properly again?
我已经构建了一个 WPF 应用程序,它现在完全可以工作了。但是,为了稍微清理一下,我希望将其移动MainWindow.xaml到我创建的视图文件夹中。完成此操作后,应用程序将无法运行,它给我一个“未知的构建错误”,但没有提供有关如何修复它的任何信息......
我应该更改什么MainWindow.xaml才能让应用程序再次正常工作?
I've already changed
我已经变了
<Window x:Class="projectname.MainWindow">
to
到
<Window x:Class="projectname.view.MainWindow">
Should I change other stuff as well?
我也应该改变其他东西吗?
回答by Rohit Vats
You don't need to update class name in xaml file unless you have changed the namespace of your class.
Most likely you haven't updated StartupUrifor App.xaml. Change it to:
除非您更改了类的命名空间,否则不需要更新 xaml 文件中的类名。最有可能你还没有更新StartupUri了App.xaml。将其更改为:
StartupUri="view/MainWindow.xaml"
from
从
StartupUri="MainWindow.xaml"
回答by AlexMelw
The answer of @Rohit Vatsis quite good!
@Rohit Vats的回答相当不错!
However that's a good point to remember: you have to change all the absolute paths(in XAML) to your resources, prepending them by a /in order to indicate that these paths are relativeto the root directory.
但是,这是一个值得记住的好点:您必须将所有绝对路径(在 XAML 中)更改为您的资源,/在它们前面加上 a以指示这些路径是相对于root directory.
Example:
例子:
From <Image Source="Assets/Loading.gif">
从 <Image Source="Assets/Loading.gif">
To <Image Source="/Assets/Loading.gif">and so on.
到<Image Source="/Assets/Loading.gif">等等。

