0

所以,我正在尝试制作一个代表 UML 建模程序中的类的 UserControl。

问题是,到目前为止,在我看来,我所做的似乎是一种错误的做法。

我希望它可以只使用一个 ItemsControl 来完成。是吗?

 <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>
4

1 回答 1

0

如果您在一个集合中显示所有这些属性和属性,您肯定会错过一些东西……您将如何显示它们周围的框?你肯定需要多个ItemsControls 来显示这些框吗?:

<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>

然后,您可以使用一些额外的属性和 a 扩展它以隐藏没有项目的部分Converter

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

当然,INotifyPropertyChanged.PropertyChangedEventHandler当它们的相关集合更新时,您必须提醒这些属性。然后你可以像这样使用它:

    <ItemsControl Grid.Row="3" BorderBrush="Black" BorderThickness="1,0,1,1" 
        ItemsSource="{Binding Methods}" Visibility="{Binding HasMethods, 
        Converter={StaticResource BoolToVisibilityConverter}}" />
于 2013-10-04T08:54:34.273 回答