0

I'm creating WPF application that needs to display about 100 (number is changing) small diamond and circle (10px) shapes in square area with image background. I know that this isn't many shapes and method doesn't really matter.

But I would like to know and learn the most efficient and WPF way to display many small moving shapes in wpf application.

Also I'd like to know what is the best way to supply "new" coordinates to drawing those elements.

What I have: For passing data I have simple array of points. That each frame (60fps) I remove array and "send" new one via event. Than screen is cleared and all shapes drawn. But it has poor performance.

I was thinking that I should use XAML and binding. But I really don't know how to set that biding. Q: How to setup binding in XAML to display many small shapes whose coordinates are supplied in list with points.

H H
  • 263,252
  • 30
  • 330
  • 514
Hooch
  • 28,817
  • 29
  • 102
  • 161
  • [This](http://stackoverflow.com/a/22325266/1136211) or [this](http://stackoverflow.com/a/25031206/1136211) may be helpful. – Clemens Dec 28 '14 at 13:23
  • @Clemens Thanks that is usefull. I see that I need to implment INotfiyProprtyChanged in my "Entites" that I draw. Is there any nice way to ask for redraw once all entites are updated? There are multiply properties that change but I would like to redraw them all at once. – Hooch Dec 28 '14 at 14:45
  • You don't do any explicit redraw. WPF cares for doing this in an efficient way. Instead, you typically bind one target property (e.g. `Canvas.Left`) to one source property (e.g. `X`). The binding has to be updated when the source property has changed. So all you need to do is to implement INotfiyPropertyChanged. In more complex scenarios, where you bind a single target property to multiple source properties (by means of a MultiBinding), you might defer raising the PropertyChanged event until all source properties have changed. – Clemens Dec 28 '14 at 14:57
  • @Clemens Thanks. I understand that WPF knows what it is doing. But how would I go about implementing it in a way that I "batch" redraw all elements of BindingList? Can I just make it so that I manually invoke PropertyChanged event? What when I bind to more than one properties of object? – Hooch Dec 28 '14 at 18:09
  • Of course you can. Your view model may raise the PropertyChanged event whenever you like. You can even pass null or an empty string as property name to signal that all properties have changed. – Clemens Dec 28 '14 at 18:14
  • @Clemens Thanks for that 'null' option. This is exactly what I was looking for. If you want you can put simple answer with what is in those comments and I'll accept it. – Hooch Dec 28 '14 at 18:36

0 Answers0