gpt4 book ai didi

c# - 使用绑定(bind)到 List 我该怎么做才能不显示控件

转载 作者:太空宇宙 更新时间:2023-11-03 22:09:11 25 4
gpt4 key购买 nike

这是我正在处理的代码:

<TextBlock TextWrapping="Wrap" Text="{Binding Objective}" Grid.Column="0" VerticalAlignment="Center" FontWeight="Bold" />
<ItemsControl ItemsSource="{Binding Problems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Rectangle Stroke="Black" Height="20" Width="20" Margin="1,0" />
</DataTemplate>
</ItemsControl.ItemTemplate>

当设置 ItemsSource 为 listBox 时。它包含:

List<Container>
(Below container properties)
- Objective: string
- Problems: List<UserControls>

看看这一行:<ItemsControl ItemsSource="{Binding Problems}" >在代码中,Problems 是一个 UserControls 列表。当我加载程序时,列表框显示来自用户控件的控件,它应该显示矩形。

我做错了什么?

最佳答案

查看 Visual Studio 的输出窗口,您将看到:

System.Windows.Data Error: 26 : ItemTemplate and ItemTemplateSelector are ignored for items already of the ItemsControl's container type; Type='XXX'

它不应用模板,因为可以直接添加项目。


关于包装控件,我的意思是创建一个类,其中包含 UserControl 的属性,例如:

 Problems : List<ProblemContainer>
public class ProblemContainer
{
public UserControl Problem { get; set; }
}

关于c# - 使用绑定(bind)到 List<UserControl> 我该怎么做才能不显示控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7294993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com