2011-06-06 61 views
18

我有我的列表框的數據模板,我必須使用所有標籤的項目資源。如果我刪除對資源的引用並只輸入標籤的文本,則不會出現錯誤。如果我嘗試使用資源,我會得到上述錯誤。未知的生成錯誤'密鑰不能爲空'

下面是數據模板:

<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資源中。這個錯誤是什麼?

+1

只是一個隨機的想法,確保所有引用的資源首先聲明,即在您的資源字典中的'DataTemplate'上方。 – dain 2011-06-06 14:36:41

+2

我想通了......我沒有爲resx添加xmlns。糟糕:s – 2011-06-06 14:44:25

回答

37

我們正在團隊中研究這個項目,我剛剛複製了使用資源的這一行......我只是忘了複製xmlns屬性。我覺得奇怪的是,這個錯誤並不是真正的描述性的,也沒有給出任何問題的真正提示。

故事的道德:如果複製代碼行,確保所有對名稱空間的引用都被複制。

+1

由於Source = {x:Static l:MainResource.Select}}中設置的資源位置錯誤,我得到了同樣的錯誤。錯誤信息比指向錯誤的地方容易讓人誤解:S – Marta 2012-07-04 09:25:32

+0

謝謝,這爲我解決了錯誤。考慮到資源部分中的每個項目都需要一個'x:Key =「...」'屬性,這個錯誤信息對於這種情況確實很糟糕。 – 2013-02-11 07:44:25

+0

我曾經因爲我刪除了診斷設置的參考,但仍然使用該設置。 – MrFox 2013-03-20 14:58:43

相關問題