Reputation: 11972
Inside a XAML
Page I'm trying to use an IValueConverter
, it's throwing an error.
IValueConverter
is in another assembly, I have added a referenceAt the top of my page I have this:
xmlns:converters="clr-namespace:Converters;assembly=Converters"
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/DialogStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<converters:NoWhiteSpaceConverter x:Key="NoWhiteSpaceConverter" />
</ResourceDictionary>
</Page.Resources>
Then I try to use it later on like this:
<TextBox Text="{Binding SomeText, Converter={StaticResource NoWhiteSpaceConverter}}" />
Can anyone see what the problem is?
Upvotes: 5
Views: 20942
Reputation: 8005
Make sure that the resources are defined before the usage (in Xaml parsing order). The easiest way is to place it into App.xaml
See also here for a similar issue: https://paulkiddie.com/the-importance-of-the-position-of-window-resources-element-in-wpf-xaml-markup/
Upvotes: 18
Reputation: 2994
In my case the resource was correctly defined before it is used but there was a wrong reference to a converter.
The problematic line was
...{Binding MyProperty, Converter={StaticResource local:MyConverter}}
and it should be without the namespace alias
...{Binding MyProperty, Converter={StaticResource MyConverter}}
where local
is a namespace alias containig the converter class and MyConverter
is the key defined in a resource in the XAML.
Upvotes: 1