2013-10-03 29 views
0

所以,我試圖做一個UserControl,它代表了UML建模程序中的一個類。使用Itemscontrol的正確方法(或類似的)

事情是,我迄今爲止所做的事似乎是在我自己眼中做錯的一種方式。

我希望可以使用一個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> 
+0

是的,這是可能的,但是我不清楚你在這裏試圖達到什麼目的。請編輯您的問題並添加更多詳細信息 –

+1

您可以使用[CompositeCollection](http://msdn.microsoft.com/en-us/library/system.windows.data.compositecollection.aspx)。 – LPL

+0

好的抱歉,這個可憐的問題。 我試圖實現一個類的表示形式,其中的屬性先列出,然後屬性等..這是很重要的順序。你懂我的意思嗎? 基本上是這樣的:http://www.tutorialspoint.com/images/uml_class_diagram.jpg –

回答

0

當然你會錯過了什麼,如果你顯示的所有這些特性和屬性在一個集合......你將如何顯示它們周圍的箱子?當然,你需要多個ItemsControl s到顯示框?:

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

然後,您可以擴展這個隱藏那些在使用一些額外的屬性沒有項目部和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}}" /> 
相關問題