【发布时间】:2014-09-17 18:06:46
【问题描述】:
我有一个名为Fly 的对象,它具有Position(点)和Orientation(双)属性。
在我的 MainViewModel 中,我有一个自定义对象 Fly称为 Flies 的集合。
苍蝇的视图是 .png 图像。我想在 MainWindow 中使用 Position 和 Orientation 的属性将 Flies 绑定到我的 Grid 以在屏幕上显示苍蝇。
我以前从未做过这样的集合绑定。我之前所做的是将集合绑定到ListBox 或ItemsControl:
<ItemsControl ItemsSource="{Binding MyCollection}">
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer>
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:ItemView/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
如何将我的对象绑定到 Grid 或任何其他控件以显示正确的位置和角度方向?
【问题讨论】:
标签: c# wpf collections