Deadzone
Deadzone

Reputation: 814

WPF Window.Resources - ambiguous reference

I'm trying to add some resources to my MainWindow.xaml file but I cant seem to open the tag Window.Resources due to ambiguous reference error.

enter image description here

This hints to me that I have some assembly that also has the name Resources, but that is not the case, I don't have any folders/classes with that name. What could be causing that? Or rather what are the other "references" causing the compiler to be unsure which one to select?

Upvotes: 0

Views: 1235

Answers (1)

dymanoid
dymanoid

Reputation: 15227

Window.Resources is an example of the special property element syntax that can be used in XAML.

Specifically, the syntax begins with a left angle bracket (<), followed immediately by the type name of the class or structure that the property element syntax is contained within. This is followed immediately by a single dot (.), then by the name of a property, then by a right angle bracket (>). As with attribute syntax, that property must exist within the declared public members of the specified type.

I've emphasized the important point that causes the error.

What you're currently doing, is trying to assign something to a property Resources in a type Window but in an instance of a Grid.

So you should either place your resources in the Window instance like this:

<Window>
    <Window.Resources>
        <!--your resources here-->
    </Window.Resources>
    <Grid>
        <!--your grid content here-->
    </Grid>
</Window>

...or you should place your resources in the Grid:

<Window>
    <Grid>
        <Grid.Resources>
            <!--your resources here-->
        </Grid.Resources>
        <!--your grid content here-->
    </Grid>
</Window>

Upvotes: 3

Related Questions