"cannot resolve symbol" in ResourcesDictionary XAML (to be merged)

540 Views Asked by At

I have one file GraphView.XAML. I have split the Resources section into two ResourceDictionary files (Vertices.xaml and Edges.xaml) which I merge as follows:

GraphView.XAML

<Window x:Class="graph_app.GraphView" ... >

<Grid>
    <Grid.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Design/Vertices.xaml"/>
                <ResourceDictionary Source="Design/Edges.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Grid.Resources>
    ...
<\Grid>

If not split the code works, but if split I get an error in the Vertices.xaml, telling me that the method ChangeVertexColor_OnClick cannot be resolved:

Vertices.XAML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:graph_app">

      <Style TargetType="{x:Type controls:VertexControl}">
          <EventSetter Event="MouseDoubleClick" Handler="ChangeVertexColor_OnClick"/>
                                                        ^^^cannot resolve symbol^^^^
      </Style>
</ResourceDictionary>

I repeat, if put in one single XAML the code works. Moreover, the ChangeVertexColor_OnClick method is implemented in GrapView.xaml.cs so it should be recognized, but somehow after the split the Vertices.xaml is losing track of the x:Class (I suppose it ignores its existence since it's a separated file).

How can I access ChangeVertexColor_OnClick from the separated ResourcesDictionary file?

Thanks

1

There are 1 best solutions below

3
On BEST ANSWER

Nothing strange is happening here :) - it just shouldn't work, because this is the way it's designed. I can see 2 possible solutions:

  1. Add codebehind file for your resource dictionary, and put your ChangeVertexColor_OnClick method there read more here
  2. Do not set MouseDoubleClick in style, but directly on controls:VertexControl (so kind of, revert your split change)