Using binding to a List<UserControl> how can I do for not showing the controls
This is the code which I'm working:
<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>
When set ItemsSource to listBox. It contains:
List<Container>
(Below container pro开发者_开发百科perties)
- Objective: string
- Problems: List<UserControls>
Look at this line: <ItemsControl ItemsSource="{Binding Problems}" >
In the code, Problems is a list of UserControls. When I load the program, the listbox is showing the controls from the user control and it's supposed to show the rectangle.
What am I doing wrong?
Look at the Output-window of Visual Studio and you will see this:
System.Windows.Data Error: 26 : ItemTemplate and ItemTemplateSelector are ignored for items already of the ItemsControl's container type; Type='XXX'
It does not apply the template as the Items can be added directly.
What i meant about wrapping your controls is that you create a class which holds a property for the UserControl, e.g.:
Problems : List<ProblemContainer>
public class ProblemContainer
{
public UserControl Problem { get; set; }
}
精彩评论