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」並且啓動事件不存在時,我有此工作。
任何線索/想法/建議。我只是想明白。
當我運行應用程序而不是@設計時,一切都按預期工作。