未知构建错误'密钥不能为空'

Joh*_*per 20 xaml

我有一个列表框的数据模板,我必须使用所有标签的项目资源.如果我删除对资源的引用,只需键入标签的文本就没有错误.如果我尝试使用资源,我会收到上述错误.

这是数据模板:

<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>
Run Code Online (Sandbox Code Playgroud)

有一点需要注意,我们正在使用其他XAML文件中的资源而没有任何问题.但是,此文件是资源字典,并已添加到app.xaml资源中.这个错误是什么?

Joh*_*per 44

我们正在团队中处理这个项目,我只是复制了使用资源的行......我只是忘了复制xmlns属性.我觉得很奇怪的是,错误并不是真正描述性的,也没有给出任何关于问题的真实提示.

故事的道德:如果复制代码行,请确保复制所有对名称空间的引用.


sfa*_*ust 8

旧帖子,但对于从谷歌搜索到这里的其他任何人......我得到了完全相同的错误,结果对我来说是不同的。

我使用完全限定的语法绑定到属性,因为我的绑定中没有目标对象。但是我是用速记来做的,这显然是完全限定的语法所不允许的。我有这样的事情:

{Binding (cmn:ElementData.ID)}
Run Code Online (Sandbox Code Playgroud)

我把它改成:

{Binding Path=(cmn:ElementData.ID)}
Run Code Online (Sandbox Code Playgroud)

繁荣,神秘的错误消失了,一切都按预期进行。显然不使用速记非常重要...

感谢链接中的Andrew Stakhov,他的评论让我知道了这一点。

  • 谢谢你,我几年前就遇到过这个问题,但它再次困扰了我......滚动到你的帖子突然激发了我大脑中的连接!啊啊,WPF 很有趣!:-s (4认同)
  • 就打同样的东西。请注意 XAML 中的转换。那里有龙 (4认同)