[英]Using binding to a List<UserControl> how can I do for not showing the controls
这是我正在工作的代码:
<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}" >
在代码中,“问题”是UserControls的列表。 当我加载程序时,列表框会显示用户控件中的控件,并且应该显示矩形。
我究竟做错了什么?
查看Visual Studio的输出窗口,您将看到以下内容:
System.Windows.Data错误:26:对于已经为ItemsControl的容器类型的项目,将忽略ItemTemplate和ItemTemplateSelector。 类型=“ XXX”
它不应用模板,因为可以直接添加项目。
我包装控件的意思是,您创建一个类,其中包含UserControl的属性,例如:
Problems : List<ProblemContainer>
public class ProblemContainer
{
public UserControl Problem { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.