我有WPF项目,并在App.xaml中定义的一些资源在其他文件中使用。当我尝试移动的App.xaml到子目录设计师不再能够找到这些资源。我的项目仍编译,因为我用'启动'事件,而不是的StartupUri。如何告诉设计师到哪里去寻找资源?它是如何知道他们在哪里时的App.xaml是项目的根源在哪里?
I have WPF project and some resources defined in App.xaml that are used in other files. When I try to move App.xaml to subdirectory designer is no longer able to find those resources. My project still compiles since I use 'Startup' event instead of 'StartupUri'. How to tell the designer where to search for resources? How it knows where they are when App.xaml is in root of project?
更新: 项目文件:
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
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:
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
MainWindow.xaml.cs
namespace WpfApplication1
{
public partial class MainWindow : System.Windows.Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
更新2: 上传压缩解决方案 http://zalil.ru/30771604 (下载将自动开始)
Update 2: Uploaded zipped solution to http://zalil.ru/30771604 (download will start automatically)
镜: http://www.speedyshare.com/files/27697250/WpfApplication1。拉链
我不能重复我到底问题。下面是我的尝试:
I can't duplicate the problem on my end. Here's what I tried:
我创建了在App.xaml中的资源风格的应用程序。让我感动的App.xaml到子目录。我有一个使用在App.xaml中的资源定义的样式(他居住在不同的目录),另一个窗口,它能够解决这个问题就好了。我说.. \到年初我原来的的StartupUri
。
I created a application with a style in the resources of App.xaml. I moved App.xaml to a subdirectory. I have another window that uses the style defined in the resources of App.xaml (he resides in a different directory) and it was able to resolve it just fine. I added ..\ to the beginning of my original StartupUri
.
我做了一些搜索,你使用的是什么版本的Visual Studio?显然,有可能是在VS2008与您问题相关的错误:
I did some searching, what version of Visual Studio are you using? Apparently there may be an bug related to your problem in VS2008:
的http://bengribaudo.com/blog/2010/08/19/106/bug-single-application-resources-entry-ignored
他说,解决有关此错误是设置 X:名称上的
。希望帮助!
属性应用
He says a workaround for this bug is to set the x:Name
attribute on Application
. Hope that helps!
编辑:我也尝试过处理启动
事件,而不是使用的StartupUri
,它仍然能正常工作
I also tried handling the Startup
event instead of using the StartupUri
and it still worked fine.
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
new MainWindow().Show();
}
}
编辑第2部分:
EDIT PART 2:
好吧,我封闭的SolidColorBrush内的ResourceDictionary这样:
Okay, I enclosed the SolidColorBrush inside a ResourceDictionary as such:
<ResourceDictionary>
<SolidColorBrush Color="LightGray" x:Key="brush" />
</ResourceDictionary>
和窗口拿起画笔。设计师不喜欢它,但是当我从的StaticResource改为DynamicResource它停止抱怨。
And the window picks up the brush. The designer doesn't like it, but when I change from StaticResource to DynamicResource it stops complaining.
编辑3:
我只是想的东西。你已经安装了Visual Studio 2010 SP1?它固定一些错误的与设计师。
I just thought of something. Do you have VS2010 SP1 installed? It fixed some bugs with the designer.
和遗憾,我的编辑2号并没有达到预期效果。我发现我的蓝色波浪线都不见了在XAML,但我没有检查的设计师。 x__x
And sorry, my edit number 2 didn't work as expected. I noticed my blue squiggles were gone in the xaml, but I didn't check the designer. x__x