Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error when adding MergedDictionary to Application.Resources WPF

I am using MVVM light to create a "quick" WPF app to test some web services. I have the whole app runiing but need to add my ResourceDictionary to the applications resources. When I add the following to the App.xaml:

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

I get the error:

Error 4 Program '' does not contain a static 'Main' method suitable for an entry point

All the help I can find on this error is related to the Build Action being set to ApplicationDefinition and this is not the problem.

Any help or guidance would be greatly appreciated.

TIA!

like image 664
RockyMountainHigh Avatar asked Dec 21 '22 15:12

RockyMountainHigh


2 Answers

I've had the same error when adding anything to the resources in App.xaml while learning MVVM Light Toolkit. The problem is caused by incorrect dictionary declaration in the <Application.Resources>, and is not related to the MVVM Light Toolkit.

The application's resources dictionary should be similar to this:

<Application ...>

    <Application.Resources>
        <ResourceDictionary>
            <!-- Global ViewModelLocator -->
            <vm:ViewModelLocator x:Key="Locator"
                                 d:IsDataSource="True" />

            <ResourceDictionary.MergedDictionaries>
                <!-- Global style -->
                <ResourceDictionary Source="Skin1.xaml" />
                <ResourceDictionary Source="Skin2.xaml" />
                <ResourceDictionary Source="Templates1.xaml" />
                <ResourceDictionary Source="Templates2.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

</Application>

This way, you get working, global resources' dictionary with the old Locator key in the same place, and new keys from dictionaries declared in listed files.

Files being loaded look like:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style TargetType="{x:Type Button}">
        <Setter Property="Height" Value="28" />
        <Setter Property="Padding" Value="12,3" />
    </Style>

    ...

</ResourceDictionary>
like image 124
Tomasz Cudziło Avatar answered Jan 11 '23 03:01

Tomasz Cudziło


Hmm what a wierd error - does your program compile and run before you add the merge dictionary section to App.xaml ?

It may well be worth checking the properties of your project - sounds like you may have it set to a Console Application - which by default has a static main method which is the start of the application.

If it's not set to Console Application - its still worth checking for the Startup object setting - this can be set to a particular class which again can be checked for a static main method as the entry point.

Entry point basically means the first thing that runs as part of the application.

HTH, Scott

like image 22
Scott Avatar answered Jan 11 '23 02:01

Scott