Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown Build Error 'key cannot be null'

Tags:

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?

like image 220
John the Ripper Avatar asked Jun 06 '11 14:06

John the Ripper


2 Answers

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.

like image 54
John the Ripper Avatar answered Sep 28 '22 06:09

John the Ripper


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.

like image 41
sfaust Avatar answered Sep 28 '22 06:09

sfaust