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.

有帮助吗?

解决方案

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).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top