将分散/重叠的图像绑定到WPF Canvas [英] Binding scattered/overlapping images to a WPF Canvas

查看:133
本文介绍了将分散/重叠的图像绑定到WPF Canvas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个GDI应用程序移植到WPF上,其中我在桌面上显示了几十个图像,然后使用GDI笔和画笔在这些图像的顶部绘制了多边形,圆形,矩形等。

I am porting a GDI application over to WPF, where I displayed several dozen images onto Form, then drew polygons, circles, rectangles, etc over the top of these images using GDI Pens and Brushes.

我开始接触WPF绑定,并希望将所有这些图像和标记图形存储在ViewModel中。

I'm starting to get the hang of WPF binding and would like to store all of these images and markup graphics in my ViewModel.

我的VM包含我自定义DrawingEntitys的ObservableCollection,DrawingEntity包含BitmapSource,Height,Width,CanvasTopLeftY和CanvasTopLeftX的DependencyProperties,我经常在集合中进行更新。我知道我的绑定正在工作,我只是无法弄清楚如何绑定并将此集合绘制到Canvas上。

My VM contains an ObservableCollection of my custom DrawingEntitys, DrawingEntity contains DependencyProperties for BitmapSource, Height, Width, CanvasTopLeftY, and CanvasTopLeftX, that I update frequently in the collection. I know my binding is working, I just can't figure out how to bind and draw this collection onto a Canvas.

我已经玩过ItemsControl和ItemsSource死亡,在这里列出的方式太多了。我可以将DrawingEntity.Bitmaps显示在画布上,但Canvas.Top不会绑定到DrawingEntity中的CanvasTopLeftY,所有内容都重叠在0,0处。我想我错过了一个明显的策略。任何想法?

I've played around with ItemsControl and ItemsSource to death, too many different ways to list here. I can display the DrawingEntity.Bitmaps onto the canvas but Canvas.Top won't bind to CanvasTopLeftY in the DrawingEntity, everything is overlapped at 0,0. I think I'm missing an obvious strategy. Any ideas?

推荐答案

查看这个答案,并对它做一些细微的修改。

Have a look at the XAML in this answer and make some slight changes to it.

这篇关于将分散/重叠的图像绑定到WPF Canvas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆