.NET Framework Bookmark and Share   
 index > Windows Presentation Foundation (WPF) > Event Driven WPF vs XNA style looping
 

Event Driven WPF vs XNA style looping

Hi Everyone,

Im very new to WPF (but very familiar with MS and development) and I have been reading up about WPF development and I read about the 2 main approaches to creating a WPF app:

1. event based (respond to the users interactions)
2. game loop style based (loop and update the positions and effects of the WPF elements ever X milliseconds)

I have seen amazing effects being produced using silverlight 3 looping style, and also amazing effects using event driven styles.

My question is really, can/should these two style ever co-exist in the same app? If I wanted to create a faded snowing effect in my background using the looping style, and at the same time have a layer over the top that is the users interaction layer, should this be done using just ONE of the two styles mentioned above?

Just wondering on opinions here.

Thanks for any advice you can give!

Cheers,
Mark
Mark Macumber
The two options you listed are usually used because of the differences in how applications update:

1) Event-Driven is usually used because your application is responding to a user.
2) Loop-Driven is used when the application needs to update, regardless of user interaction. (Games, ie: XNA, often use this because the screen is updating even if the user is doing nothing).

The two are not mutually exclusive. In fact, it's quite common to see an event based application start a timer that will trigger an "event" in a repeated "loop". Typically, this is done differently than a loop-driven application, but the effect is similar.

I would recommend not using a full render loop style loop in a GUI-based application, however. They are very oriented towards games and attempts to have a near-realtime experience, and tend to cause user interaction to suffer. Instead, use a timer, such as the DispatcherTimer, or subscribe to CompositionTarget.Rendering when you need to have a loop-driven style. You can easily remove the event handler when you are done with your continual update.


Reed Copsey, Jr. - http://reedcopsey.com
  • Marked As Answer byMark Macumber Wednesday, September 23, 2009 12:53 AM
  • Proposed As Answer byBigsby Tuesday, September 22, 2009 11:23 PM
  •  
Reed Copsey, Jr.
The two options you listed are usually used because of the differences in how applications update:

1) Event-Driven is usually used because your application is responding to a user.
2) Loop-Driven is used when the application needs to update, regardless of user interaction. (Games, ie: XNA, often use this because the screen is updating even if the user is doing nothing).

The two are not mutually exclusive. In fact, it's quite common to see an event based application start a timer that will trigger an "event" in a repeated "loop". Typically, this is done differently than a loop-driven application, but the effect is similar.

I would recommend not using a full render loop style loop in a GUI-based application, however. They are very oriented towards games and attempts to have a near-realtime experience, and tend to cause user interaction to suffer. Instead, use a timer, such as the DispatcherTimer, or subscribe to CompositionTarget.Rendering when you need to have a loop-driven style. You can easily remove the event handler when you are done with your continual update.


Reed Copsey, Jr. - http://reedcopsey.com
  • Marked As Answer byMark Macumber Wednesday, September 23, 2009 12:53 AM
  • Proposed As Answer byBigsby Tuesday, September 22, 2009 11:23 PM
  •  
Reed Copsey, Jr.
Hi Reed,

Thanks for the info, looks like that pretty much answered my question perfectly. I suspected that there would be a common mechanism to achieve the looping/Events mix.

Cheers
Mark
Mark Macumber

You can use google to search for other answers

Custom Search

More Threads

• Window Icon Propery no longer working
• MediaElement vs WMP
• How to Add a System.Windows.Controls.MediaElement in a Resource file
• XAML data binding involving external UserControl fails
• Scrollviewer with GridSplitter
• Selected item in ComboBox not displaying when list of items are non-Visual
• Export .docx to .XPS without the Office Component
• Copy metadata from one image to another
• DataTemplate - Change Control based on Selection
• HowTo check if validation failed