【发布时间】:2016-05-27 18:15:07
【问题描述】:
我有一个ObservableCollection<ControlMachine>,其中每个ControlMachine 是一个UserControl,用于显示有关一台计算机的信息。
public static ObservableCollection<ControlMachine> ListControleMachine =
new ObservableCollection<ControlMachine>();
我尝试使用绑定显示集合
<Grid ForceCursor="True" x:Name="grid2" OpacityMask="{x:Null}" Margin="10,38,10,10" Background="#FFF5F6F6">
<ItemsControl ItemsSource="{Binding ListControleMachine}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type Brush}">
<Rectangle Canvas.ZIndex="3" Width="100" Height="100" Canvas.Top="100" Canvas.Left="100" Fill="blue"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
我的用户控件没有显示在Grid 中,带有此代码。怎么了?
问题:将此类 ControlMachine 置于其他设备之下的最佳做法是什么?
那些 ControlMachine 可以关闭和展开,我找不到 clean 方法来更新任何情况下的用户控件位置。
附件:您认为在这种情况下使用UserControl 是一种好习惯还是我应该使用Template 或StackPanel?
你将如何实现它?
【问题讨论】:
标签: c# wpf binding user-controls