1
我是WPF的初学者。我的App.xaml看起来像下面WPF:当不从App.xaml引用Shell时访问应用程序资源
的App.xaml
<Application x:Class="ContactManager.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<Color x:Key="lightBlueColor">#FF145E9D</Color>
<SolidColorBrush x:Key="lightBlueBrush"
Color="{StaticResource lightBlueColor}" />
</Application.Resources>
,因为我想演示第一种方法我没有设置的StartupUri。我做app.xaml.cs
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var appPresenter = new ApplicationPresenter(
new Shell(), new ContactRepository());
appPresenter.LaunchView();
}
下面我有一个名为“SearchBar.xaml”它引用“lightBlueBrush”作为StaticResource的用户控件。
当我尝试在设计器中打开“Shell.xaml”时,它告诉我:“shell.xaml”无法在设计时加载,因为它表示无法创建“SearchBar.xaml”类型的实例。
当我使用另一个Visual Studio实例调试devenv.exe时,它告诉我它无法访问我在app.resources中创建的Brush。
如果你正在做Presenter的第一种方法,那么如何访问资源?
当startupURI是“Shell.xaml”并且启动事件不存在时,我有此工作。
任何线索/想法/建议。我只是想明白。
当我运行应用程序而不是@设计时,一切都按预期工作。