James Joshua Street
James Joshua Street

Reputation: 3409

WPF how to reference application resource from merged dictionary?

So if I have a converter in the resource dictionary for my app like so:

<Application.Resources>
    <ResourceDictionary>
      <Converters:ColorToBrushConverter x:Key="ColorToBrushConverter" />


      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="ResourceDictionaries/GraphViewerBrushes.xaml" />
        <ResourceDictionary Source="ResourceDictionaries/ColorPickerResources.xaml" />
      </ResourceDictionary.MergedDictionaries>



    </ResourceDictionary>
  </Application.Resources>

How can I reference the converter from within one of the external xaml files? or is this not possible? i know i could just reinstance another converter there, but that seems wasteful.

Upvotes: 0

Views: 221

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564333

You can use DynamicResource instead of StaticResource to reference the converter. This will cause it to look up the resource dynamically, which should succeed as it's part of the Application resources.

That being said, I typically just create another instance, as it is simpler, and a converter has very, very little overhead to create (since it should have no state).

Upvotes: 2

Related Questions