伪无限网格
我在这里遇到了一些设计问题。
我有一个视图:
<ItemsControl x:Name="CellVMs">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Row"
Value="{Binding Position.Y}" />
<Setter Property="Grid.Column"
Value="{Binding Position.X}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
它绑定到视图模型的集合,该集合具有一个位置属性,其中的样式使用该属性将其定位在 ItemPanelTemplate 上。 (每个单元格只有一个视图模型,并且网格单元格大小固定)
1)我希望网格是伪无限的,即随着 EditorVM 的添加和减少,网格应该动态添加和删除 Row\Col 定义,并且有应该始终有足够的网格,并且应该始终有足够的空间来填充父视图。
2)在我的包含视图模型中,我导入一个具有 Grid 属性的 IGridEditor 实现实例。如何将 ItemsPanelTemplateGrid 绑定到 IEditor.Grid?
现在,我将 CellVM 添加到 IGridEditor 方法中的集合,然后当包含虚拟机导入实例时,将包含虚拟机的 CellVM 集合设置为实例集合,并且项目控件使用 Caliburn.Micro 约定绑定到该集合。
顺便说一句,我正在使用 Caliburn.Micro\MEF。
谁能帮我解决这个问题吗?
编辑:
一直试图理解这一点,但我一无所获。
我唯一能找到的是
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid x:Name="EditorGrid"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
在我的 viemodel 中:
[Import("EditorGrid", typeof(Grid))]
public Grid EditorGrid { get; set; }
以及类中相应的 Export,它具有将内容添加到网格的方法/
I've got a bit of a design issue here.
I've got a view:
<ItemsControl x:Name="CellVMs">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Row"
Value="{Binding Position.Y}" />
<Setter Property="Grid.Column"
Value="{Binding Position.X}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
which is bound to a collection of viewmodels, that have a position property which the style there uses to position it on the ItemPanelTemplate. (Only one viewmodel per cell, and the grid cells are fixed size)
1) I would like that Grid to be pseudo-infinite, ie as EditorVMs get added and subtracted, the Grid should dynamically add and delete Row\Col Definitions, and there should always be enough Grid, and there should always be enough to fill the parent view.
2) In my containing viewmodel, I import an IGridEditor implementation instance which has a Grid property. How can I bind the ItemsPanelTemplateGrid to the IEditor.Grid?
Right now, I add the CellVM's to a collection in the IGridEditor's methods, then when the containing vm imports the instance, sets the containing vm's CellVM collection to the instances collection, and the item control binds to that using Caliburn.Micro's conventions.
I'm using Caliburn.Micro\MEF btw.
Can anyone help me figure this out?
Edit:
Been trying to understand this, but I'm coming up empty.
Only thing I can find is
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid x:Name="EditorGrid"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
and in my viemodel:
[Import("EditorGrid", typeof(Grid))]
public Grid EditorGrid { get; set; }
and a corresponding Export in class that has the methods to add things to the grid/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个自定义
Grid
,根据需要自动添加行或列:(不确定
GetVisualChild
是执行此操作的最佳位置,但这是我能找到的最好的位置)You could create a custom
Grid
that automatically adds rows or columns as needed:(not sure
GetVisualChild
is the best place to do this, but it's the best I could find)