我有我的列表框的數據模板,我必須使用所有標籤的項目資源。如果我刪除對資源的引用並只輸入標籤的文本,則不會出現錯誤。如果我嘗試使用資源,我會得到上述錯誤。未知的生成錯誤'密鑰不能爲空'
下面是數據模板:
<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>
有一點要注意,我們所使用的資源,沒有任何問題其他XAML文件。然而,這個文件是一個資源字典並被添加到app.xaml資源中。這個錯誤是什麼?
只是一個隨機的想法,確保所有引用的資源首先聲明,即在您的資源字典中的'DataTemplate'上方。 – dain 2011-06-06 14:36:41
我想通了......我沒有爲resx添加xmlns。糟糕:s – 2011-06-06 14:44:25