【发布时间】:2014-11-24 17:01:17
【问题描述】:
我有一个 ContainerViewModel 继承 Conductor<T>.Collection.AllActive 和一个 PanelViewModel 继承 Screen 并且其生命周期由 ContainerViewModel 控制
我的ContainerView 使用templated ItemsControl 来呈现由指挥管理的我的Collection<T>。此视图当前使用UniformGrid 控件,items 按添加到Conductor<T>.Collection 的顺序显示(Items 被删除并通过event 添加到run-time,该event 提供@ 987654336@).
我想改用Grid,预定义数量为Columns 和Rows,如下所示:
+------------------------------------------------------+
| 1 | 2 | 3 | 4 |
| 0,0 | 0,1 | 0,2 | 0,3 |
+------------------------------------------------------+
| 5 | 6 | 7 | 8 |
| 1,0 | 1,1 | 1,2 | 1,3 |
+------------------------------------------------------+
单个数字表示Position 和Points 下方的Coordinates 和Row Index 和Column Index。
我知道我可以执行以下操作:
<ItemsControl ItemsSource="{Binding Items}">
<!-- ItemsPanelTemplate -->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<!-- ItemContainerStyle -->
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Column"
Value="{Binding ColumnIndex}" />
<Setter Property="Grid.Row"
Value="{Binding RowIndex}" />
</Style>
</ItemsControl.ItemContainerStyle>
<!-- ItemTemplate -->
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我对上面的问题是 PanelViewModel 要显示为 Content 需要 ColumnIndex 和 RowIndex 属性的概念才能挂钩。我对此并不完全满意,因为我认为管理定位是 ContainerViewModel 的责任。
有没有一种方法可以实现这一点,只有ContainerViewModel 知道Position 概念?
【问题讨论】:
标签: c# wpf xaml caliburn.micro