[英]How to move App.xaml and not to break designer?
我有WPF项目,并在App.xaml中定义了一些其他文件中使用的资源。 当我尝试将App.xaml移到子目录设计器时,不再能够找到那些资源。 由于我使用'Startup'事件而不是'StartupUri',所以我的项目仍然可以编译。 如何告诉设计师在哪里寻找资源? 当App.xaml位于项目根目录时,如何知道它们在哪里?
更新:项目文件:
App.xaml中:
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="startup">
<Application.Resources>
<SolidColorBrush Color="LightGray" x:Key="brush" />
</Application.Resources>
</Application>
App.xaml.cs
namespace WpfApplication1
{
public partial class App : System.Windows.Application
{
private void startup(object sender, System.Windows.StartupEventArgs e)
{
new MainWindow().Show();
}
}
}
MainWindow.xaml:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300" Background="{StaticResource brush}" />
MainWindow.xaml.cs
namespace WpfApplication1
{
public partial class MainWindow : System.Windows.Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
更新2:将压缩的解决方案上传到http://zalil.ru/30771604 (下载将自动开始)
镜像: http : //www.speedyshare.com/files/27697250/WpfApplication1.zip
我无法重复这个问题。 这是我尝试过的:
我在App.xaml的资源中创建了具有样式的应用程序。 我将App.xaml移到了子目录。 我有另一个窗口,该窗口使用App.xaml资源中定义的样式(他位于其他目录中),它能够很好地解决它。 我在原始StartupUri
的开头添加了.. \\。
我做了一些搜索,您正在使用什么版本的Visual Studio? 显然,VS2008中可能存在与您的问题有关的错误:
http://bengribaudo.com/blog/2010/08/19/106/bug-single-application-resources-entry-ignored
他说,解决此错误的方法是在Application
上设置x:Name
属性。 希望有帮助!
编辑:我也尝试处理Startup
事件而不是使用StartupUri
,它仍然可以正常工作。
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
new MainWindow().Show();
}
}
编辑第2部分:
好的,我将SolidColorBrush封装在ResourceDictionary中,如下所示:
<ResourceDictionary>
<SolidColorBrush Color="LightGray" x:Key="brush" />
</ResourceDictionary>
然后窗户拿起刷子。 设计器不喜欢它,但是当我从StaticResource更改为DynamicResource时,它不再抱怨。
编辑3:
我只是想到了什么。 是否已安装VS2010 SP1? 它修复了设计师的一些错误 。
很抱歉,我的编辑编号2未能按预期工作。 我注意到我的蓝色曲线在xaml中消失了,但是我没有检查设计师。 x__x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.