类型为“...”的值无法添加到“UIElementCollection”类型的集合或字典中
当我通过 XAML 添加自定义控件时,出现以下错误。可能的原因是什么?
“...”类型的值无法添加到“UIElementCollection”类型的集合或字典中
<Grid x:Name="QuantityDetail" DataContext="{StaticResource ViewModel}">
<GroupBox>
.....
<Label Style="{StaticResource ResourceKey=LabelValue}">Min</Label>
<!-- The following control -->
<NumericUpDown></NumericUpDown>
.....
</GroupBox>
</Grid>
I am getting the following error when I am adding a custom control via XAML. What can be the possible reason?
A value of type '...' cannot be added to a collection or dictionary of type 'UIElementCollection'
<Grid x:Name="QuantityDetail" DataContext="{StaticResource ViewModel}">
<GroupBox>
.....
<Label Style="{StaticResource ResourceKey=LabelValue}">Min</Label>
<!-- The following control -->
<NumericUpDown></NumericUpDown>
.....
</GroupBox>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题是我的解决方案中没有引用一个 DLL(由 NumericUpDown 控件引用)。实际上
NumericUpDown
控件不是我的控件,它存在于不同的 DLL 中。该控件引用了 System.Windows.Controls.Input.Toolkit.dll。现在我在我的解决方案中引用它并且一切正常。Problem was that I was not referencing to one DLL (which is referenced by
NumericUpDown
control) in my solution. ActuallyNumericUpDown
control is not my control, it is present in a different DLL. And this control was referingSystem.Windows.Controls.Input.Toolkit.dll
. Now I am refering it in my solution and things are working.我在我们的项目中也遇到了这个智能感知问题(构建仍然是可能的),但没有外部控制。所以也许有人需要这个答案......
这里的“问题”是,
UserControlXYZ.xaml
被声明为UserControl
,但UserControlXYZ.xaml.cs< /code> 没有继承自
UserControl
。因此,我必须在 xaml.cs 中添加 UserControlXYZ :UserControl (尽管 Resharper 表示基本类型已指定并且可以删除)。I had this intellisense problem as well in our project (building was still possible), but not with an extern control. So maybe someone needs this answer...
The "problem" here was, that the
UserControlXYZ.xaml
was declared asUserControl
but theUserControlXYZ.xaml.cs
did not inherit fromUserControl
. So I had to add the UserControlXYZ :UserControl in xaml.cs (even though Resharper says base type is already specified and can be removed).编译器声称您的控件不是
UIElement
(我怀疑它在撒谎),您的控件继承自什么?The compiler claims that your control is not an
UIElement
(i doubt that it is lying), what does your control inherit from?就我而言,我在 XAML 面板中使用
而不是
。 (这是一个愚蠢的错误,我现在要去喝咖啡。)In my case, I used a
<GridView>
instead of a<DataGrid>
in a panel in XAML. (A stupid mistake and I am going to have a coffee right now.)