【问题标题】:WPF : Access Application Resources when not referencing Shell from App.xamlWPF:不从 App.xaml 引用 Shell 时访问应用程序资源
【发布时间】:2010-05-23 18:38:42
【问题描述】:

我是 WPF 的初学者。我的 App.xaml 如下所示

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”作为静态资源。

当我尝试在设计器中打开“Shell.xaml”时,它告诉我:“shell.xaml”无法在设计时加载,因为它说它无法创建“SearchBar.xaml”类型的实例。

当我使用另一个 Visual Studio 实例调试 devenv.exe 时,它​​告诉我它无权访问我在 app.resources 中创建的画笔。

如果使用 Presenter first 方法,如何访问资源?

当 startupURI 是“Shell.xaml”并且启动事件不存在时,我已经开始工作了。

任何线索/想法/建议。我只是想明白。

当我运行应用程序时,一切都按预期工作,而不是@设计时间。

【问题讨论】:

    标签: wpf resources app.xaml presenter-first


    【解决方案1】:

    base.OnStartup(e) 应该是函数的最后一行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多