32

I have a data template for my listbox and I must use project resources for all the labels. If I remove the reference to the resource and just type in the text for the labels there are no errors. If I try to use the resources I get the above error.

Here is the data template:

<DataTemplate x:Key="CheckBoxDatePickerItemTemplate"> <Border BorderThickness="1" CornerRadius="3" BorderBrush="{StaticResource GreenBorderBrush}"> <StackPanel Orientation="Horizontal" Background="#208897EB" MinWidth="370"> <CheckBox Focusable="False" IsChecked="{Binding IsChecked}" VerticalAlignment="Top"/> <ContentPresenter Content="{Binding Name, Mode=OneTime}" Margin="2,2" Width="140" VerticalAlignment="Top"/> <StackPanel Orientation="Vertical" Visibility="{Binding DateDataVisible}"> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{Binding IncludeNullDates}" VerticalAlignment="Center" Focusable="False"/> <Label Content="{x:Static resx:Resources.Label_IncludeEmptyDates}" Margin="2,2" Width="170" VerticalAlignment="Center"/> </StackPanel> <StackPanel Orientation="Horizontal"> <ContentPresenter Content="{x:Static resx:Resources.Label_From}" Margin="2,0" Width="50" VerticalAlignment="Center"/> <DatePicker SelectedDate="{Binding StartDate}" Margin="2,2" Width="150" /> </StackPanel> <StackPanel Orientation="Horizontal"> <ContentPresenter Content="{x:Static resx:Resources.Label_To}" Margin="2,0" Width="50" VerticalAlignment="Center"/> <DatePicker SelectedDate="{Binding EndDate}" Margin="2,2" Width="150" /> </StackPanel> </StackPanel> </StackPanel> </Border> </DataTemplate> 

One thing to note we are using the resources in other XAML files with no problems. This file however is a resource dictionary and is added to the app.xaml resources. What's with this error?

0

2 Answers 2

66

We are working on this project in a team and I just copied the line for using resources... I just forgot to copy the xmlns attribute as well. What I find strange is that the error isn't really descriptive and doesn't give any real hints as to what the problem is.

Moral of the story: if copying lines of code make sure that all references to namespaces are also copied.

Sign up to request clarification or add additional context in comments.

3 Comments

I have got the same error because of wrong set resource location in Source={x:Static l:MainResource.Select}}. The error message is rather misleading than pointing where error is :S
Thanks, this fixed the error for me. This error message is truly terrible for the situation considering that in the resources section each item needs an x:Key="..." attribute.
I had it because I removed a reference to diagnostic settings but still used the setting.
15

I was getting the same exact error and it turned out to be something different for me.

I was binding to properties using a fully qualified syntax because I didn't have a target object in my binding. However I was doing it with shorthand and that's apparently not allowed with fully qualified syntax. I had something like this:

{Binding (cmn:ElementData.ID)} 

I changed it to:

{Binding Path=(cmn:ElementData.ID)} 

And boom, cryptic error gone and everything worked as expected. Apparently VERY important to not use shorthand with this...

Thanks to Andrew Stakhov at this link whose comment tipped me off to this.

3 Comments

Thank you, I had encountered this problem years ago but it stumped me once again... scrolling to your post suddenly fired the connections in my brain! Aaah, WPF is fun! :-s
Just hit the same thing. Beware casting in XAML. There be Dragons
I was getting some obscure ArgumentNullException with absolutely no information every time I selected an item in a ListBox and this turned out to be the issue. Madness.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.