19

I have a Styles.xaml that groups many ResourceDictionarys inside a MergedDictionary.

I imported Styles.xaml in my UserControl.Resources

<UserControl.Resources>
    <ResourceDictionary Source="Dictionaries\Styles.xaml" />
</UserControl.Resources>

but when I try to add a converter

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Dictionaries\Styles.xaml" /> <--! Exception -->
        </ResourceDictionary.MergedDictionaries>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    </ResourceDictionary>
</UserControl.Resources>

it raises

ArgumentNullException: Value cannot be null.
Parameter name: item

Wrapping the converter inside another MergedDictionary has no effect.
How can I solve this?
Thank you all!


SOLVED

I eventually figured it out: the Exception was raised inside one the .xaml files, but Visual Studio does not provide enough info to locate the faulty line.
Following code does work.

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Dictionaries\Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    </ResourceDictionary>
</UserControl.Resources>
Sergio
  • 2,078
  • 3
  • 24
  • 41
  • It should work with the how you are implementing before the edit. can you share your style.xaml? – Nitin Sep 05 '13 at 02:47
  • 1
    yeah the second code should be okay (probably there's an issue in your Styles.xaml itself), if you want to use the 3rd code though, you need to add the second resourcedictionary inside the mergeddirectory tags – dnr3 Sep 05 '13 at 03:34
  • thank you @dnr3 your comment solved the problem it was a style in the gerarchy of styles dictionaries that had a problem, so Styles.xaml had a problem too and it all didnt work, fixed and now working, thanks you all – Sergio Sep 05 '13 at 11:02
  • You should post your answer, had your same problem and now it works. – IssamTP Nov 14 '22 at 07:55

1 Answers1

20

Try this

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/PROJECTNAMESPACE (TestProject.Something);component/Dictionaries/Styles.xaml" /> 
        </ResourceDictionary.MergedDictionaries>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    </ResourceDictionary>
</UserControl.Resources>
Contango
  • 76,540
  • 58
  • 260
  • 305
123 456 789 0
  • 10,565
  • 4
  • 43
  • 72
  • same error on the longer line: value cannot be null. It's not a matter of the resource being found, because if i changed something it says it couldnt resolve the resource, it has to be something different, imho – Sergio Sep 05 '13 at 01:21
  • can you provide the callstack – 123 456 789 0 Sep 05 '13 at 03:38