使用App.xaml中的ResourceDictionary自动完成

问题描述 投票:0回答:1

这是我目前的项目架构:

Program.Startup.csproj
--- Styles
------ MyStyles.xaml
--- App.xaml

Program.View.csproj
--- MainWindow.xaml
--- SettingsView.xaml
--- ...

我正在使用我的app.xaml为我的所有控件加载我的样式:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary  Source="Styles/MyStyles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

每当我在主窗口中使用样式时,在设计时就无法找到它。在开发视图/窗口时,有没有办法让自动完成工作并停止1000“未找到错误”?

c# wpf xaml controltemplate
1个回答
-1
投票

窗口是内容控件。

因此,如果您愿意,可以将其内容切换出来。

将主窗口置于与入口点完全不同的项目中没有多大意义。

如果你想要foo,你可以新建一个foo实例并使MainWindow.Content = myFoo。

想要吧吧....你可以将它的内容设置为bar的实例。

无论如何,无论您的主要解决方案是什么,都可以添加其他项目。

您可以添加现有项目,以便您的代码在同一解决方案中可见。

因此,你的意见将是。

然后在app.xaml中,您可以合并入口点解决方案中的资源字典,并使用pack notation合并来自其他项目的资源字典。

这是一个实时app.xaml的副本。

<Application x:Class="ScenarioEditor.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Startup="Application_Startup"
         >
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary  Source="pack://application:,,,/UILib;component/Resources/Geometries.xaml"/>
            <ResourceDictionary  Source="pack://application:,,,/UILib;component/Resources/ControlTemplates.xaml"/>
            <ResourceDictionary  Source="pack://application:,,,/UILib;component/Resources/FontResources.xaml"/>
            <ResourceDictionary  Source="/Resources/ScenarioEditorResources.xaml"/>
            <ResourceDictionary  Source="pack://application:,,,/UILib;component/Resources/UILibResources.xaml"/>
            <ResourceDictionary  Source="pack://application:,,,/UILib;component/Resources/HypsoColoursRD.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

我的解决方案是Scenario Editor和ScenarioEditorResources,其中有几个其他项目被引用,它们的资源字典也被合并。我在visual studio中打开场景编辑器解决方案。

当我编辑其中一个引用项目中的东西时,UILib然后合并所有资源。

您也可以添加设计资源字典,但看起来它会从exe加载到dll中。

不是传统的工作方式。

© www.soinside.com 2019 - 2024. All rights reserved.