简体   繁体   中英

Autocompletion with a ResourceDictionary in App.xaml

Here is my current project architecture:

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

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

I am using my app.xaml to load in my styles for all my controls:

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

Whenever I use a style in my mainwindow, it can't be found during design time. Is there a way to get autocomplete working and stop the 1000 "not found errors" when developing a view / a window?

A Window is a content control.

You can therefore switch out it's content if you wanted to.

It doesn't make much sense having your mainwindow in a totally different project to the entry point.

If you wanted foo in it you can new up an instance of foo and make MainWindow.Content= myFoo.

Want bar instead.... you can set it's content to an instance of bar.

In any case, whatever your main solution is can have other projects added.

You can add existing project(s) so your code is all there visible in the same solution.

And hence your views will be.

Then in app.xaml you can merge resource dictionaries from the entry point solution and use pack notation to merge resource dictionaries from other projects.

Here's a copy of a live app.xaml does that.

<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>

My solution is Scenario Editor and ScenarioEditorResources is in that, there are several other projects referenced and their resource dictionaries also merged. I work by opening the scenario editor solution in visual studio.

When I edit stuff that's in one of those referenced projects, UILib then all the resources are merged ok.

You could alternatively add a design resource dictionary but that looks like it'd be loaded from an exe into a dll.

Not the conventional way to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM