我有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