Provide value on ‘System.Windows.Data.Binding’ threw an exception

Today is the second time I receive the exception message: “Provide value on ‘System.Windows.Data.Binding’ threw an exception” when using the WPF DataTemplateSelector.

Problem: Static resources declaration order *matter* !!! So you should not declare the instance of your DataTemplateSelector before actually declaring DataTemplates (see code sample below).

<!-- data template selector NOT HERE-->
<local:CustomDataTemplateSelector
	x:Key="_customDataTemplateSelector"
	FirstDataTemplate="{StaticResource _firstDataTemplate}"
	SecondDataTemplate="{StaticResource _secondDataTemplate}"
	ThirdDataTemplate="{StaticResource _thirdDataTemplate}"
/>

<DataTemplate x:Key="_firstDataTemplate">
	<TextBlock Text="dataTemplate 1"/>
</DataTemplate> 

<DataTemplate x:Key="_secondDataTemplate">
	<TextBlock Text="dataTemplate 2"/>
</DataTemplate> 

<DataTemplate x:Key="_thirdDataTemplate">
	<TextBlock Text="dataTemplate 3"/>
</DataTemplate> 

<!-- data template selector -->
<local:CustomDataTemplateSelector
	x:Key="_customDataTemplateSelector"
	FirstDataTemplate="{StaticResource _firstDataTemplate}"
	SecondDataTemplate="{StaticResource _secondDataTemplate}"
	ThirdDataTemplate="{StaticResource _thirdDataTemplate}"
/>
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.