开发者

WPF : Access Application Resources when not referencing Shell from App.xaml

开发者 https://www.devze.com 2022-12-31 14:14 出处:网络
I am beginner in WPF. My App.xaml looks like below app.xaml <Application x:Class=\"ContactManager.App\"

I am beginner in WPF. My App.xaml looks like below

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>

I do not set the startupuri since I want to a presenter first approach. I do the following in app.xaml.cs

  protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        var appPresenter = new ApplicationPresenter(
            new Shell(), new ContactRepository());
        appPresenter.LaunchView();
    }

I have a usercontrol called "SearchBar.xaml" which references "lightBlueBrush" as a staticResource.

When I try to open "Shell.xaml" in the designer it tells me : The "shell.xaml" cannot be loaded at design time because it says it could not create an instance of type "SearchBar.xaml".

When I debugged the devenv.exe using another visual studio instance it tells me that it does not have access to the Brush I created in app.resources.

If one is doing a Presenter first approach, how does one access resources?

I had this working when the startupURI was "Shell.xaml" and the startup event was not present.

Any clues/ideas/suggestions. I am just trying to开发者_如何学C understand.

Everything works as expected when I run the application just not @ design time.


base.OnStartup(e) should be the last line in the function.

0

精彩评论

暂无评论...
验证码 换一张
取 消