canton7 / Stylet

A very lightweight but powerful ViewModel-First MVVM framework for WPF for .NET Framework and .NET Core, inspired by Caliburn.Micro.
MIT License
996 stars 144 forks source link

In XAML, Resharper/VS complains that ApplicationLoader needs a key (reports as error) #44

Closed estaylorco closed 6 years ago

estaylorco commented 6 years ago

Hello,

(Using VS 2017 and .Net 4.7)

I started with nothing but your Startup NuGet package (and the Stylet NuGet package, of course). App.XAML looks like this:

<Application.Resources>
    <s:ApplicationLoader>
        <s:ApplicationLoader.Bootstrapper>
            <local:Bootstrapper />
        </s:ApplicationLoader.Bootstrapper>
    </s:ApplicationLoader>
</Application.Resources>

There is a red squiggly line under . The complaint is that a key is necessary. When I add one, however, the new complaint is that ApplicationLoader must be a member of a resource dictionary in order to have a key. When I surround the ApplicationLoader with a resource dictionary, that solves the problem: all squigglies disapper. But no window appears when the application runs.

Also, despite the red squiggly (before surrounding with a dictionary), the application still runs. Resharper/VS reports an actual error in the App.XAML file, which is disconcerting.

What's going on here?

Thank you.

canton7 commented 6 years ago

Looks like Resharper is getting confused - that XAML is perfectly valid (s:ApplicationLoader is a ResourceDictionary, and it's valid to have a ResourceDictionary assigned to the Application's Resources property).

You can also try this, see if Resharper likes it:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <s:ApplicationLoader>
                <s:ApplicationLoader.Bootstrapper>
                    <local:Bootstrapper/>
                </s:ApplicationLoader.Bootstrapper>
            </s:ApplicationLoader>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
estaylorco commented 6 years ago

That did the trick! You know, I was close: I did manage to get to the ResourceDictionary, but I hadn't thought to go further with MergedDictionaries. I will bring this to the attention of the Resharper team.

Thank you!