Custom AnimationClock for WPF - wpf

I'm searching for a way to have a custom AnimationClock. Every Storyboard has it's own and under heavy load the animations get out of sync. Since I need to have separate Completed events making one big Storyboard impossible...
The solution I'm currently investigation is to write a custom AnimationClock class, so that the animation stays in sync as the AnimationClock for all of the affected Storyboards starts and stops at exactly the same time.
I did not found a way to implement this yet, and internet searches have revealed only unanswered threads until now. Has anyone found a solution to create a custom clock?
Thanks !

Maybe my article (in Italian translated with google) can help you http://translate.google.it/translate?js=n&prev=_t&hl=it&ie=UTF-8&layout=2&eotf=1&sl=it&tl=en&u=http%3A%2F%2Fblogs.ugidotnet.org%2Fleonardo%2Farchive%2F2011%2F01%2F08%2Fsincronizziamo-le-animazioni-con-wpf.aspx&act=url. You need to call ReSync() every time you go out of sync.

Related

running an openGL engine in WPF in a separate thread

I have an openGL rendering engine coded in unmanaged C++, and I want to embed this in a WPF application. After a little research, I managed to do it by using the handle of a windows forms panel in a windowsformshost, as explained here (2nd solution):
http://www.codeproject.com/Articles/127141/Unmanaged-C-OpenGL-Drawing-and-C-WinForms-WPF-inte/?display=Mobile
So far good. The problem is, I need the render to be real time, and when some UI operation takes too long (like populating a property grid), the render flickers.
Then I guess I need to do the rendering in a separate thread. I tried to use this approach:
http://blogs.msdn.com/b/dwayneneed/archive/2007/04/26/multithreaded-ui-hostvisual.aspx
But it does not work because it seems i cannot place a windowsformshost inside a HostVisual (http://social.msdn.microsoft.com/Forums/en-AU/wpf/thread/124cc95c-a9c6-4aca-a5fc-4f959ea715c3)
So, any idea how can I do this?
If you use double-buffering then it should never flicker. See the section "How to Avoid Flickering?" in the first article you linked to. You can also try inserting Application.DoEvents() calls inside code that takes a long time to execute. Just some suggestions as an alternative to the added complexity of using a threaded solution.
EDIT: just realized WPF does not support DoEvents(), but there are alternatives: http://nmarian.blogspot.com/2007/09/doevents-in-wpf.html

WPF - Navigation blocks application (poor performance)

I have a WPF application which generates MIDI notes (a sequencer).
Besides the UI thread, there is a timer thread which triggers notes. In general, the timing is ok, but I have the following problem: Whenever I do any navigation, the application seems to "block" (i.e. the timer "stumbles" and the output stops for a short time). This happens when I e.g. open a new window or perform a navigation on a navigation window.
This also happens when I navigate to a page which is already instantiated and has been shown before.
Does anyone have any ideas?
EDIT: I think the actual question is: Does anyone know of a way to make navigation faster?
I'm not sure, but wouldn't your eventhandler (_midiInternalClock_Tick) be executed in your UI thread?
So the MidiInternalClock might be executing in another thread, but the handling of the ticks wouldn't. Like I said, not sure about this.
You might want to separate the code that works with the Midi toolkit to a separate class and then construct the clock en handle it's events in a different thread.
If that doesn't help, I'm at a loss. I guess you would then best ask your question on the CodeProject page.

How to measure screen render time in WPF

I am attempting to measure the performance for a WPF based application. Currently we have code that times how long it takes to add the content to the WPF render tree. At this point, control is returned to our program. The problem is that there is still a lag before content is displayed on the screen by WPF. For complicated rendering trees, this can be a matter of seconds.
Can you recommend a method to determine when WPF has completed rendering to the screen? I would like these tests to be fully automated and not rely on someone sitting around with a stopwatch.
[update]
Thanks for the suggestions so far.
I have tried waiting for the Loaded and ContentRendered events, but both fire before the content makes it to the screen.
It looks like others are having this issue. I have tried the steps suggested at
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/693fbedb-efa6-413e-ab66-530c6961d3fb/ but still haven't been able force my code to wait for the rendering to complete.
You may use this solution: http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/
Did you take a look at the WPF Performance suite? You might be able to see the performance and pinpoint problematic code.
You could end the timer after the control's Loaded event since that occurs after the Rendering is complete.
You should use the event ContentRendered of Window.
This will fire every time there's a full rendering sequence, and you can time that.

WPF Resource Refreshing problem

I using multilanguage solution from this thread Multilanguage in WPF
But i have problem with automaticaly Resource refreshing after language was changed.
Old strings stay in old language, new is traversed propertly.
What is easiest solution to solve this problem, for example refresh all resources in application?
I've worked with localization as well. The problem with it is the changes you make in culture info while your app is running, isn't going to be shown in the UI. The values for the controls do change, but the change isn't notified to the ui of the control. For as far as i've been googling this, i haven't found a reasonable solution for offline applications. Even InitializeComponents isn't doing the trick.
The only solution, allthough i don't like that one very much, is to change the culture, then start up a batch which will close and restart the app with the chosen cultureinfo.
The reason why i don't like this is because you rely on an external file (the batch) and not all applications can just be restarted like that. But it might do the trick.
The easiest solution I've found is to simply reopen the window - if you work with MVVM all the state (or the important state anyway) is preserved in the ViewModel(s) and only the view is refreshed.
I haven't used the extension you linked to, but any of these more advanced systems should handle refresh automatically. In my case, I just used {x:Static res:ResourceName} references to the resources, and refreshed the view when the language changed. Granted, I don't allow changing the language in the more complicated screens... :)

How to make windows form UI responsive?

This is a common problem for all developers, I am looking for the best solution to make windows forms UI responsive.
I have an animated GIF file to show progress of my calcuation on windows form. I took a picture box control and placed animated gif into that. now when my calcuation starts - the animaged gif freezes. I want the reverse, the animation should be visible when i am running the calculation.
Any to the point thoughts? A simple solution is to display a progress bar to the user while doing complex calculations behind the scene
My app is a single threaded application, and I want a simple solution, not looking for multi-threads, or background worker kind of technologies.
Any help?
Multiple threads would be my recommendation. A bit messy first time you try ;)
Simplest model: One thread for the GUI, and one thread for whatever work you need to do.
Check this link.
Application.doevents
You place it in the loop. It gives the UI the time to do its things.
Well, the only real way to do 2 things at once (like do calculations, and still keep responsive) is to use threads. If you won't want to explicitly use threads, then check to see if there are any asynchronous calls you can use to do it in the background. Aside from that, do a lot of Application.DoEvents calls wherever you do lots of work.
I'm going to have to site Jeff on this one:
Coding Horror: Is DoEvents Evil?
"simple solution to display a progress to the user while doing complex calculations behind the scene ?"
"not looking for multi-threads, or background worker kind of technologies."
Which of those wishes is more important to you? You'll have to choose one or the other.

Resources