Jaime Rodriguez On Windows Phone, Windows Presentation Foundation, Silverlight and Windows 7
Over the last month, several people have asked me why CPU is so high on the healthcare demo ... I usually
Last week, Christoph emailed me asking about the perf the same day that I was installing the demo to show it , so I "peeked" ... In summary: I cut the CPU consumption on my laptop ( 2.1 GHz ) significantly due to a possible tiny bug.. Taskmgr tells me CPU went down between 20 and 40% .. specially for the first screen... In my laptop, the first screen is running at around 3% CPU, and the second screen is running at around 25 % ... [Both of these used to be much higher]
Here are the findings
OK, those are a few of my findings while on a 2 hour flight to San Jose... I am zipping the code and putting it here.
When I have time I will check with Karsten to see if that is worth re-publishing .. I think if we are going to re-publish we should add a couple of extra changes like:
Hope that helps some ... If I ever have time, I will look deeper into the second screen... I think that is still has a lot of room ... if any one peeks and finds stuff let us know..
Tim Sneath ( my work boss) emailed me asking how it went , and since I am typing if for my team I thought: "what the heck ... just publish it..."
I had the pleasure of attending and presenting at Desktop Matters last Friday .. It is the "hard-corest" Java conference I have ever attended (disclaimer, I have only attended 2 java conferences: JavaOne and OSCON) ... The conference focuses on client java technologies, a lot of people from Sun's Java2D and Swing team presented.. Also, some influentials building interesting java stuff..
Here are my thoughts:
On the conference: it was awesome... A small group of Java influentials talking with the Java leaders (Hans Muller, Chet Haase, Richard Bair, etc.) .. there was nothing held back either direction.. The Sun team shared challenges and road-map... the community provided good feedback.. I had a blast and learned a lot ... Read some of their reports here.. The event reminded me of what at Microsoft we call Software Design Reviews ( SDRs ) ... Some of you reading this post might have attended one of these ... You know that it is hard to buy that kind of access, well on the Java client community you might have the answer in this conference.. A nice touch different from the SDR was Ben Galbraith the organizer who kept it light .. making equal fun of every one there
On Java SE and Swing: I was surprised and (as a technologist) happy to see progress on java and Swing ; their 'filthy rich' demos looked pretty good ; That said, I still think they are very far behind Microsoft (both Windows forms but specially WPF) in tooling, customization, richness, etc.. You can definitely do good stuff on Java, if you are willing to write a bit of code or hire experienced devs.. [yes, I of course acknowledge they do it for the cross-platform promise.. if you must go x-platform and can't go AJAX, I think that is one of the best choices out there]
On my presentation/message: When I arrived, I had a deck with 40 slides covering the ins of WPF ( templates, styles, resources, etc.) by the second day I had changed it based on a private conversation with Hans Muller - I pitched him on XAML and he seemed overwhelmed with properties, triggers, styles, etc.. but he really got the "oh, makes better tools" idea..
So, in the end, I presented a simple (much slower-paced ):
I did two demos:
The feedbackI was very surprised on the 'kudos' ... Quite a few people came to me afterwards and shared kind thoughts... I got a lot of "I get your experience message"; and "I love what WPF can do", "XAML seems very neat", etc..
My best two take aways...
That is it ... I hope the conference repeats next year .... If it does, I would recommend it if you are a Java client developer ...I also hope I don't get fired for a post w/ the word java so much ... My first test to see how far I can take it ....
it only took less than an hour for some one to ask why my last post has this code:
Matrix m =PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;double dx = m.M11;double dy = m.M22;
The multiple choice answer is: a) habit, not paying attention b) filling space, not paying attention c) not paying attention
The code gets the horizontal (M11), vertical (M22) DPI on my system.. The actual value are divided by 96 ... [going back to WPF's device independent logical units in wpf being 1/96 of an inch]... so for example, my system at 144 DPI so I get 1.5 ...
Technically, WindowsFormsHost does NOT need that code; it is supposed to do that translation for you, if you give it a windows forms control that is not sized.
Sorry ..
Several times I have had needed to put WPF content in front of Windows Forms control hosted in a WPF app...
Unfortunately, this is a limitation in the interop story, WindowsFormsHost elements are always drawn on top, and don't get affected by z-order ...
The first time I did this, I was working with an imaging company, so it was easy as their activex rendered onto a bitmap already.. so we used that as a workaround: create a bitmap, and then 'replace' the control with the bitmap at specific times/triggers..
The next time, I tried to use the same workaround .. but this time, I wrote some 'ugly' code to make a simple winforms control render into a bitmap ... [trust me it was ugly, took me a day+, used interop, ec.] ... Now, I see this post from LLobo telling me there was an API for this ... way to make me feel dumber than usual :( ...
So, I am putting it here so no one else misses it like I did, also as a reference as now I have to email Robert -sorry man - to tell him to replace our old code :) The API is VisualTreeHelper.GetDrawing.. Wrote the simplest test, here is kinda what it looks like [will do for a quick airspace demo :) ]
Explanation of the screen above: The Left hand side is a WindowsFormsHost control hosting a MonthCalendar Windows Forms controls. . The RHS is a Rectangle witha DrawingBrush of the WindowsFormsHost in the LHS... Across both UIElements, there is supposed to be a red rectangle overlayed [imagine this could be any other element or a flying animation, etc.] ... Notice that on the Left, the Red rectangle is behind the WindowsFormsHost. . on the right, you get the right visual experience. . You could easily use this strategy to swap the WindowsFormsHost in and out ... don't you think??
The code is trivial, I packaged it inside a Dispatcher callback - I don't think it is absolutely needed, but felt safer, trying to make sure windowsformshost has been drawn] ....
void Window1_Loaded(object sender, RoutedEventArgs e){Matrix m =PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;double dx = m.M11;double dy = m.M22;
System.Windows.Forms.MonthCalendar mc = new System.Windows.Forms.MonthCalendar();mc.Width = (int)(wfHost.Width * dx);mc.Height = (int)(wfHost.Height * dy);wfHost.Child = mc;
this.Dispatcher.BeginInvoke (System.Windows.Threading.DispatcherPriority.Background , new DispatcherOperationCallback(delegate{ DrawingGroup dg = VisualTreeHelper.GetDrawing( wfHost ); DrawingBrush db = new DrawingBrush ( dg );db.TileMode = TileMode.None;db.Stretch = Stretch.None; rect.Fill= db ;
return null;} ), null );
}
Full sample is here.
I tested with several custom windows forms controls seems to work ... That said, I could not get Lester's demo to work with the IE frame ... I believe this same code will work for Win32 interop (HwndHost) but did not test it, if you try it and it does not work ping me..