C# 使用Itemscontrol(或类似工具)的正确方法
所以,我试图在UML建模程序中创建一个表示类的UserControl 问题是,到目前为止我所做的在我看来似乎是一种错误的方式 我希望它可以只用一个ItemsControl来完成。。是吗C# 使用Itemscontrol(或类似工具)的正确方法,c#,wpf,itemscontrol,C#,Wpf,Itemscontrol,所以,我试图在UML建模程序中创建一个表示类的UserControl 问题是,到目前为止我所做的在我看来似乎是一种错误的方式 我希望它可以只用一个ItemsControl来完成。。是吗 <Border BorderThickness="1" BorderBrush="Black"> <DockPanel> <TextBox Text="ClassName" HorizontalAlignment="Center" DockPanel.Doc
<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>
如果在一个集合中显示所有这些属性和属性,您肯定会错过一些东西。。。你会如何展示他们周围的盒子?您确实需要多个
项控件来显示框吗
<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>
当然,在更新这些属性的相关集合时,您必须向INotifyPropertyChanged.propertychangedventhadler
通知这些属性。然后你可以这样使用它:
<ItemsControl Grid.Row="3" BorderBrush="Black" BorderThickness="1,0,1,1"
ItemsSource="{Binding Methods}" Visibility="{Binding HasMethods,
Converter={StaticResource BoolToVisibilityConverter}}" />
是的,这是可能的,但是我不清楚您在这里想要实现什么。请编辑您的问题并添加更多详细信息。您可以使用。好的,很抱歉这个糟糕的问题。我正在尝试实现一种类似类的表示,首先列出属性,然后列出属性,依此类推。。按这个顺序很重要。你知道我的意思吗?基本上是这样的:@jesperplantener您可能想看看类似的东西,使用MVVM。
<ItemsControl Grid.Row="3" BorderBrush="Black" BorderThickness="1,0,1,1"
ItemsSource="{Binding Methods}" Visibility="{Binding HasMethods,
Converter={StaticResource BoolToVisibilityConverter}}" />