我有WPF项目和App.xaml中定义的其他文件中使用的一些资源。当我尝试将App.xaml移动到子目录时,设计师不再能够找到这些资源。由于我使用'Startup'事件而不是'StartupUri',因此我的项目仍在编译。如何告诉设计师在哪里搜索资源?当App.xaml位于项目的根目录时,它如何知道它们在哪里?如何移动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
我看到我做了不同的事情。感谢您的来源。我会修补更多。 – 2011-03-30 22:22:05
我已经更新了我的答案。希望有所帮助! – 2011-03-30 22:32:34
你安装了SP1吗? – 2011-03-30 23:26:31