0

So, i'm trying to make a UserControl that represents a class in a UML modeling program.

The thing is, what I have done so far seems like a wrong way to do it in my own eyes.

I was hoping it could be done using just a single ItemsControl.. Is it?

 <Border BorderThickness="1" BorderBrush="Black">
    <DockPanel>
        <TextBox Text="ClassName" HorizontalAlignment="Center" DockPanel.Dock="Top"/>

        <ItemsControl  Name="attributeList" ItemsSource="{Binding Attributes}" Margin="5,0,5,0" DockPanel.Dock="Top">
        </ItemsControl>

        <ItemsControl Name="propertiesList" ItemsSource="{Binding Properties}" Margin="5,0,5,0" DockPanel.Dock="Top">
        </ItemsControl>

        <ItemsControl Name="methodsList" ItemsSource="{Binding Methods}" Margin="5,0,5,0" DockPanel.Dock="Top">
        </ItemsControl> 

    </DockPanel>
</Border>
bland
  • 1,968
  • 1
  • 15
  • 22
Jesper Plantener
  • 229
  • 3
  • 16
  • Yes, it's possible, however it is unclear to me what you're trying to achieve here. Please edit your question and add more details – Federico Berasategui Oct 03 '13 at 16:43
  • 1
    You could use a [CompositeCollection](http://msdn.microsoft.com/en-us/library/system.windows.data.compositecollection.aspx). – LPL Oct 03 '13 at 16:45
  • Okay sorry for the poor question. I'm trying to achieve a class-like representation, where the attributes are listed first, then the properties and so on.. It's important in that order. Do you know what I mean? Basically something like this: http://www.tutorialspoint.com/images/uml_class_diagram.jpg – Jesper Plantener Oct 03 '13 at 16:51
  • @jesperplantener You may want to take a look at [my example](http://stackoverflow.com/a/15821573/643085) of a similar thing, using MVVM. – Federico Berasategui Oct 03 '13 at 17:04

1 Answers1

0

Surely you'd be missing out on something if you displayed all of these attributes and properties in one collection... How would you display the boxes around them? Surely you need multiple ItemsControls to display the boxes?:

<Grid Width="100" TextBlock.TextAlignment="Center">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <ItemsControl Grid.Row="0" BorderBrush="Black" BorderThickness="1" 
        TextElement.FontWeight="Bold">Customer</ItemsControl>
    <ItemsControl Grid.Row="1" BorderBrush="Black" BorderThickness="1,0,1,1" 
        ItemsSource="{Binding Attributes}" />
    <ItemsControl Grid.Row="2" BorderBrush="Black" BorderThickness="1,0,1,1" 
        ItemsSource="{Binding Properties}" />
    <ItemsControl Grid.Row="3" BorderBrush="Black" BorderThickness="1,0,1,1" 
        ItemsSource="{Binding Methods}" />
</Grid>

You could then extend this to hide sections that have no items in using a few extra properties and a Converter:

public bool HasMethods
{
    return Methods.Count > 0;
}

Of course, you'll have to alert the INotifyPropertyChanged.PropertyChangedEventHandler to these properties when their related collections are updated. Then you could use it like this:

    <ItemsControl Grid.Row="3" BorderBrush="Black" BorderThickness="1,0,1,1" 
        ItemsSource="{Binding Methods}" Visibility="{Binding HasMethods, 
        Converter={StaticResource BoolToVisibilityConverter}}" />
Sheridan
  • 68,826
  • 24
  • 143
  • 183