In his Styling A ScrollViewer/Scrollbar In WPF article Sacha Barber explains how to do exactly what the article’s title claims. :)
Archive for the 'WPF' Category
Today’s Sites/Blogs
- Started to “bump” into the Smashing Magazine quite often nowadays. Usually it collects interesting Internet resources related to web development (notably CSS, HTML, AJAX, etc.) and design (user interfaces, fonts, new ideas, etc.), and also has some tutorial-like or how-to-like posts (e.g. about PNG optimization, common mistakes, etc.). Really nice! Webdesigner Depot, Line25 Web Design Blog, and Presidia Creative all have similar concept.
- Windows Presentation Foundation SDK by Windows Presentation Foundation SDK writers and editors. Might be more interesting, but OK nevertheless.
- Expression Blend and Design – The team blog of the Expression Blend and Design products
WPF: Data Virtualization
WPF: Data Virtualization article at CodeProject shows a different approach to the data virtualization for WPF ItemsControls – a collection class providing data virtualization with large data sets.
WPF: A Graph Control
WPF : A graph control by Sacha Barber at CodeProject is a very nice article showing how to build a graph control in WPF, in a very detailed and elaborated way. The control looks great, by the way :) .
WPF Video Playback Problems
There is one severe problem with video playback in WPF/Silverlight that, for some reasons unknown to me, is getting very little (almost none) attention from both the community and Microsoft. Basically, it boils down to WPF being absolutely unable to properly play video content. Let me explain by using the following diagram:

First line shows video frames as they are in the video content. Second line depicts variable frame rate of the WPF renderer – as you know, WPF is changing the frame rate dynamically, and CPU load will affect frame rate too. There are two possible outcomes:
- WPF is using vsync (version 1), i.e. it synchronizing rendering to the screen with the screen refresh frequency. This is what you will get on Vista, and sometimes on XP (normally XP video drivers are not using vsync). The resulting video shown on the screen will have variable duration of frames, and the viewer will be present with artifacts like skipped video frames, “jerky” playback, where motion is not “smooth”/uniform, etc.
- WPF is not using vsync (version 2). It is the case normally seen on XP. The resulting video is even worse, as there is the tearing effect present now – upper and lower parts of the displayed video frame are not matching. This problem is not present on some XP machines, e.g. I do not see it on my home PC, while it is present on 100% of other machines.
This is a bit oversimplified picture, but good enough for our purpose. In reality, the resulting on-screen picture will depend also on the screen refresh frequency, but artifacts will be more or less the same. In both cases the video playback it totally unacceptable though.
The issue is very serious, and, unfortunately, it is unsolvable in terms of today’s WPF. I think it will be not solved in the near future either, as solving it would require WPF to adopt constant-frame rate rendering paradigm, and synchronizing it with the display refresh rate. This is not likely to happen, as it is a drastic change to the fundamentals of WPF, and, at the same time, it will waste resources in non-video related applications (now WPF can decide what frame rate it will use, and can dynamically change it, e.g. dropping frame rate for “still” scenes and increasing it when animations start).
In our software we had to go through a lot of extra pain to “overcome” this issue – we render video using DirectShow by incorporating Win32 host into our WPF application and implement all kinds of “tricks” to allow WPF content to get into the video window airspace (to display OSD’s, menus, etc.) by using e.g. clipping regions (say Goodbye! to transparency though). There are a few third party projects out there (WPF MediaKit by Jeremiah Morrill is an excellent example) that allow one to mix DirectShow and WPF, but none of them will fix the above mentioned issues, as the resulting picture is rendered by WPF renderer and all the artifacts will be there still.
Probably, for majority of people this is not really an issue (at least until you point them to it; after that they can see it on their own and they become very annoyed), especially if you are playing some kind of home-made content from the YouTube (although YouTube has HD content nowadays too), but it is completely unacceptable for people at least somehow concerned about the video playback quality. DVD/DivX player costing $30 will not have these problems, so it is difficult to explain why $1000 machine (33 times more expensive!!!) cannot produce even remotely as good video playback on $2000 HD TV set.
In addition to these video playback problems, WPF on XP suffers from the tearing issue not only during video playback, but also during “normal” WPF animations. And this has even more profound effect, as it makes it impossible to implement animated WPF applications on XP.
Microsoft’s reaction to the tearing issue on XP is problematic. We have tried to approach them via all possible channels – Microsoft Connect program, Microsoft Metro program, newsgroups, personal contacts, everything. They either deny the issue, or say that it is unsolvable for XP in general case, so they are not going to solve it (but they could easily solve it for something like 95% of all XP installations by solving it at least for ATI and Nvidia cards), or they say that they will not solve it for XP anymore, as XP is not available so nobody cares. And this last reaction is problematic again, as the issue is present not only on Windows XP Home/Pro, but on Windows XP Embedded and Windows Embedded Standard as well. These OS’s will be around for some time still, and Windows 7 Embedded will not come before 2010 and, being Vista-based, will be a resource hog – something not necessarily good for embedded system.
JavaFX
It seems that Sun can say now, “rumors about my death were greatly exaggerated”. Recently they rather quietly released JavaFX – a rich client platform (what has happened to thin client dreams of Sun and alike? huh? ;) for creating and delivering rich Internet experiences across “all the screens of your life” (they are using this phrase all over the place, and it sucks, to be honest, but go figure).
From what they show in their videos, it looks rather like WPF/Silverlight for Java. In other words, it is the presentation layer for the Java platform. Performance-wise it looks rather good (OK, no idea what hardware was running those demos). For example, they were playing 9 (yes, nine!) video streams simultaneously, but then, who the f#$k needs 9 videos playing at the same time!? It is the same f#$*%ng old useless BS that Microsoft is showing all the time! Of course, it remains to be seen if it can play all this video content without framerate issues that plaque WPF/Silverlight. JavaFX Script is a declarative scripting language behind JavaFX.
Sun is promising to make JavaFX multiplatform, capable of running on desktop, mobile, TV and other Java-enabled consumer platforms, but so far they have desktop version only. Then, as far as I understand, development tools are not necessarily ready yet (judging from their sentence “JavaFX technology will provide a suite of tools and authoring solutions that enable unprecedented collaboration between designers and developers”). If they will deliver all these promises, Microsoft might get into deep trouble with WPF, as Java’s inability to provide good UIs were one of the main reasons why many were choosing .NET over Java on the client side (I am not discussing platforms – .NET 3.5 vs Java 6 – just presentation parts). What Sun has already made right, in my opinion, is their selection of Adobe PhotoShop and Illustrator as a designer tools, as these are light-years ahead of Microsoft Expression Designer.
Future will show, what will come out of all this, but the good point is that Microsoft will get some competition in this field, and might eventually do something to fix its platform’s shortcoming (though unlikely – so far they are taking extremely defensive and ignorant stance regarding WPF/Silverlight problems).
WPF Blogs
- DevDave – Dave Relyea’s Silverlight Blog by Dave Relyea [MSFT]- really much info about Silverlight and WPF, including layout and panels
- Ruurd Boeke Enterprise development and technobabble – layouts, panels, controls, etc.
.NET/WPF Obfuscators
We have recently purchased PreEmptive Solutions Dotfuscator (which sounded like a good idea when we were making decision about it), but to be honest I am not very happy about it: it cannot properly handle WPF projects and you have to perform a lot of “voo-doo dances” to get at least some protection there (and all that while costing s|-|1t-load of money). This pushed me to do a new round of evaluations of competing products, and I have found few that are really interesting:
- .NET Reactor (about 150€) is a really powerful tool with lots of features (code and resource protection, code encryption, support for .NET 1.1, 2.0, 3.0, 3.5, CF 1.0 and 2.0, ASP.NET, Mono, can merge assemblies, remove IL code, generate native executables, etc., etc., etc.). Additionaly there is a licensing system, but I have not tried it yet. Despite it claims supporting .NET 3.5 I did not manage to protect our WPF assemblies with it, but all other assemblies were protected like a charm.
- DeepSea Obfuscator (about 200€). This obfuscator’s list of features is not much shorter, but few outstanding points are support for WPF assemblies, and declarative obfuscation, where the obfuscation process can be controlled by applying obfuscation-related attributes to your code. I managed to protect our WPF assembly with it, but resulting assembly is crashing when I’m entering one specific screen. I guess this crash can be eliminated by using attribute-based obfuscation and removing some properties/classes from the protection process (which is not that good, to be honest, as it means extra work, howewer small it is).
- {smartassembly} (about 350€-650€, depending on version) looks really impressive as well. It was able to protect WPF assembly and, it seems that the abovementioned crash is not present here; well, it is with certain settings related to obfuscation, but it can be easily eliminated by tweaking settings. Control flow obfuscation seems to be much stronger than that of the DeepSea, and there are some additional protection settings that make lives of Reflector, ILDASM and others really miserable (e.g. invalid metadata streams).
It seems that to get decent level of protection we will have to use either {smartassembly}, or both .NET Reactor and {smartassembly} (in case {smartassembly} would be not able to provide the same protection level for “normal”=non-WPF assemblies as .NET Reactor does – remains to be seen).
Webcam Control with WPF
Webcam control with WPF or how to create high framerate player with DirectShow by using InteropBitmap in WPF application by Tamir Khason shows how to do exaclty what it claims to show :) in a way alternative to what Jeremiah Morrill is proposing (now, I do not have an opinion as of which is better or worse – they both have their uses).
Side Note Unfortunately, you cannot play decent quality video in WPF application (meaning in WPF “airspace”) no matter what you do – it has to do with non-constantness of the WPF rendering frame rate (and, on XP, add here WPF tearing artefacts), and I do not see how it can be fixed in the future as this problem is rooted extremely deeply in the core of WPF rendering pipeline. Microsoft knows about this issue, but does nothing to fix it.
Crack.NET
Crack.NET is a runtime debugging and scripting tool that gives you access to the internals of a WPF or Windows Forms application running on your computer. It nicely rounds the Snoop and Mole for Visual Studio group, as it allows you to “walk” the managed heap of another .NET application, and inspect all values on all objects and types. In addition, you are able to write and execute IronPython scripts that run inside the target application.
Josh Smith is the author, and has a nice introductory page for the tool.
ItemsControl: A to Z
Dr. WPF has a great series titled ItemsControl: A to Z. Following parts are available so far:
XamlPadX
There is version 4 of the Lester Lobo’s XamlPadX – a replacement for XamlPad with few interesting add-ons like Command Interpreter, ability to view control styles, color selection, etc.
As expected (even earlier than expected, to be honest), today Microsoft released Silverlight 2 and Expression Blend 2 SP1.
Had no time to blog – work really takes all my time nowadays (and “nowanights” too :)…
Microsoft has finally released a newer version of Expression Blend. Now it is called Expression Blend 2 SP1 Preview or Expression Blend 2 SP1 RC Preview, depending on where on Microsoft’s site you are reading it, hinting that we will likely get the final release version rather sooner than later (in a month or two, who knows?). This is the version that marks the end of Expression Blend 2.5 CTP – Microsoft will not release newer versions of 2.5 CTP anymore; instead, all 2.5 features migrated to Blend 2 SP1, which is not bad IMHO.
I had not much time to play with it so far, but what I have seen looks really promising. For example, Blend finally stopped crashing all the time in case there were errors in XAMLs (or rather in code-behind); now it is displaying meaningful error messages about these problems, so you finally get a chance to fix it. Of course, there are still many problems which Microsoft most likely will not fix in this release anymore. For example, the Resources pane really sucks big time: if you have many resource files (and you have them if you are skinning your app), it is virtually impossible to navigate in them – they are sorted in weird order known only to Microsoft itself (or, maybe, it is just random?), and there is no way to do anything about it, e.g. sort them in alpha order.
In any case, it is really big step in the right direction. I would recommend to move to 2.0 SP1 ASAP in case you are using 2.5 CTP and developing WPF applications (cannot say about Silverlight/Silverlight 2 as I am not using those).
Introduction to D3DImage
Dr. WPF published Introduction to D3DImage on CodeProject. The release of .NET 3.5 SP1 made possible a whole new level of WPF-DirectX interop: a custom DirectX scene can now be composed with a WPF scene using the new WPF’s D3DImage feature.
OMFG! One guy (OK, OK, he partially reused the work of another guy) made what whole Expression team was unable to do for ages – IntelliSense for Expression Blend add-in! WOW! Works in Blend 2.5.
Well, Josh Smith is always producing good stuff: his Using RoutedCommands with a ViewModel in WPF at CodeProject is really cool!
WPF Weather Reader User Control
Found Weather Reader User Control (on CodePlex), that has the functionality of Vista weather gadget. The control parses a XML weather feed from the Internet and updates an object model that is data bound to the UI. The design is extensible and can be adapted to any general feed with minimal changes.
New Features in .NET/WPF 3.5 SP1
- StringFormat by Lester Lobo – allows custom string formatting in bindings
- ScrollViewer.IsDeferredScrollingEnabled; AlternationCount; IEditableCollectionView by Lester Lobo - perceived performance improvement, setting alternating properties on rows of an items control, add/remove/edit items in a collection
WPF Application Localization
WPF Runtime Localization article on CodeProject describes one way to do it. Interesting approach is to use WPF Localization Extension available freely on CodePlex. And then there is an article that goes in the same direction: WPF Localization – On-the-fly Language Selection.
Today’s Sites/Blogs
- Luca Bolognese’s WebLog [MSFT] – C# mainly (e.g. a C# library to write functional code, creating an immutable value object in C#, LINQ, and other nice C# things)
- LukeH’s WebLog by Luke H? [MSFT] – interesting C# articles mostly, with some F#
- Charlie Calvert’s Community Blog [MSFT] – VS IDE and LINQ articles, some WPF, etc.
- Yet Another Language Geek by ??? – C# functional programming, advanced C# topics (e.g. partial methods, iterators), some other interesting stuff
- The Mellow Musings of Dr. T by ??? – C# functional programming (not updated though)
Today’s Sites/Blogs
- Pedram Rezaei’s Ramblings – a bit of everything: Parallel Extensions for .NET, WCF, WPF…
- Fabulous Adventures In Coding by Eric Lippert [MSFT] – generics, advanced .NET topics, covariance vs contravariance, etc.
- Managed World blog by Jason Olson [MSFT?] – a lot of interesting information about new .NET things like lamdas, Managed Extensibility Framework, F#, etc.
- Ayende @ Rahien by Oren Eini – testing, mocks, a lot of code snippets (including Code of the Week), etc.
- Kirill Osenkov – QA, advanced C#, etc.
- Sree’s ventures in code space by ? – debugging, C#, extension methods, etc.
WPF Blogs
WPF blogs from Microsoft and ex-Microsoft guys/gals primarily (as well as guys that know their way around the Microsoft):
- 2008.04.10 Jim Nakashima’s blog – really much info about WPF, XAML, Studio…
- 2008.04.09 WPF Disciples – new blog by Dr. WPF and other WPF gurus. Looks promising.
- 2007.10.09 ScottGu’s Blog by Scott Guthrie – interesting WPF, WCF, Silverlight, etc. info
- 2006.10.31 Jim Galasyn’s Learning Curve – interesting exercises in WPF mixed with “strange” things like performance monitors, Windows Media Player, etc.
- 2006.10.31 Adventures with WPF by Martin Grayson - nice examples of various things you can do with WPF: 3D user interfaces, user experience enhancing, tutorials, etc.
- Tim Sneath has pretty long list of Windows Presentation Foundation Blogs
- Kevin@Work (new) and Okoboji: a lake, a mythical university (old) by Kevin Moore – Bag-O-Tricks and others
- Nick on Windows Presentation Foundation by Nick Kramer
- Beatriz Costa – cool snippets and many nice things
- IRhetoric by Karsten Januszewski
- See Win App by [jnak] – a bit of everything: design mode detection, adorners, licensing, etc.
- Soaked in CIDER! by Subhag Oak – Adorners, SafeHandles, Clipboard, Tools, you-name-it
- Greg Schechter’s Blog - not really much about WPF, but still interesting resource about Desktop Window Manager, WDDM, their interoparability
- Urban Potato by Brian Pepin – all kinds of cool things
- Rob Relyea by Rob Relyea – nice blog with lots of stuff
- house of mirrors by Pete Blois – tons of good things, including Snoop utility, attached properties, etc.
- BenCon by Ben Constable – great blog about ItemControl, IScrollInfo, templates, item collections, attached properties (including “remora pattern”), etc.
- Dan Crevier’s Blog – DataModel-View-ViewModel pattern, virtualizing panels, etc.
- Tales from the Smart Client by John Gossman – Model-View-ViewModel, performance, interesting WPF articles, etc.
- Jeff Simon’s Blog – another guy from Max team talks about all kinds of things.
- Blog on WPF by Mike Hillberg – “random interesting things”
- Henry Hahn – mostly performance-related: declarative .Tier, frame rate, optimizations, etc.
- WPF SDK by WPF SDK Team
- WPF Text Blog by WPF Team – it is what it says…
- IanG on Tap by Ian Griffiths – interesting things about WPF and not only…
- ATC Avalon Team – Avalon team’s blog. A bit (way too?) outdated, but still has some interesting info…
- Robert A. Wlodarczyk’s Blog – a blog about “imaging, media, and effects”
- Marcelo’s WebLog by [?]- drag and drop, tracing, ADO.NET, etc.
- Lester’s piece on WPF by Lester Lobo - nice snippets, all kinds of WPF related things, including XamlPad+ (XamlPad replacement)
And here are blogs by ex-Microsoft people (sad, that they are not at MS anymore):
- notstatic.com by Robby Ingebretsen – nice things. Has not been updated recently, but now it is picking up again. Check his Kaxaml replacement of XamlPad.
- fortes.com by Filipe Fortes – few demos and screencasts, mostly mix06-related
- jfo’s coding by Jessica Fosler – many samples, snippets, tips, etc.
Channel 9
Other blogs:
- 2008.07.10 WPFopoly by Matt Duffin: guy is creating a game similar but unrelated to Monopoly – from scratch. A lot of panels-related things.
- 2008.07.10 Pixel in Gene by Pavan Podila (?) – mostly related to 3D
- 2008.07.10 sachabarber.net by Sacha Barber – I guess no need to introduce this guy :)
- 2008.07.10 Andrew Smith
- 2008.07.10 Alan Le’s Vertigo Blog – a lot of info about resources and WPF/Silverlight
- 2008.07.10 Karl on WPF by Karl Shifflett
- 2007.08.26 Nick Thuesen has few interesting articles about panels and other WPF and non-WPF things
- 2007.08.26 the WPF way… – Pavan Podila’s blog has interesting stuff, but very little code (its title says “‘the Approach, rather than the Solution”)
- Josh Smith on WPF (and the old blog) – great blog about all kinds of things like “smart” ResourceDictionaries, controls’ customization, etc.
- theWPFblog by Lee Brimelow – a lot of samples and nice ideas
- Sheva’s TechSpace’s Blog by Yong Zhou (aka Sheva, footballism on MSDN forums). His blog is great and guy knows a lot.
- On .Net Client Stuff by [?] – not a bad blog with lots of goodies about Vista gandets, WPF/ActiveX interoperability, tips, etc.
- Jan-Cornelius Molnar – quite cool blog with some nice tips about Dispatcher.Invoke (obvious, but still), customizing WPF window border (like in Max), etc.
- dotnet mania by Eric Burke – PanelLayoutAnimator, some XAML snippets
- Chaz by [?] – a bit outdated, but a lot of nice ideas and samples (skinning, SkewTransform, Elliptic Control, etc.)
- Ruurd Boeke: Enterprise development and techno babble by Ruurd Boeke – some interesting posts about databinding
- XamlXaml.com by Michael Emmons – nice snippets and bits…
- Douglas Stockwell’s WebLog – interesting things about WPF, generics, DWM Thumbnails in WPF, dynamic method generation, Impossible WPF, …
- DeveloperZen.com by Eran Kampf – tons of interesting resources about WPF and not only
- Laurent Bugnion (GalaSoft) - nice blog about WPF, .NET, Web Services, etc.
Recently Microsoft released Composite Application Guidance for WPF (for VS2008 and .NET 3.5).
Quote: “The Composite Application Guidance for WPF is designed to help you more easily build enterprise-level Windows Presentation Foundation (WPF) client applications. This guidance will help you design and build flexible composite WPF client applications—composite applications use loosely coupled, independently evolvable pieces that work together in the overall application.
The Composite Application Guidance for WPF can help you split the development of your WPF client application across multiple development teams. In this type of application, each team is responsible for the development of different pieces of the application, which are seamlessly composed together. The guidance includes a reference implementation, reusable library code (named the Composite Application Library), documentation, QuickStart tutorials, and hands-on labs.”
.NET 3.5 SP1 Beta and Real Life
While there are many nice improvements in the .NET 3.5 SP1 Beta (see here, here or here), there are problems too, unfortunately… Yesterday we spent half a day trying to understand why absolutely simple and legitimate piece of XAML is not opening in Blend 2. The code looks like this (relevant part of it):
<Window.Resources>
<Style TargetType="{x:Type ListBoxItem}" x:Key="LBIS">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
</Style>
<ControlTemplate TargetType="{x:Type ContentControl}"
x:Key="CT">
<ListBox ItemContainerStyle="{StaticResource LBIS}"/>
</ControlTemplate>
</Window.Resources>
<ContentControl Template="{StaticResource CT}"/>
Simple, isn’t it? Well, it is not! Blend is choking on the Setter of FocusedVisualStyle in the ListBoxItem’s LBIS style with ” XML namespace prefix does not map to a namespace URI, so cannot resolve property ‘FocusedVisualStyle’. FocusedVisualStyle can be substituted by almost any other property of the ListBoxItem, although some of them, e.g. Width or Opacity will work.
On the other hand, following XAML will open nicely (ListBox is not inside of the template anymore):
<Window.Resources>
<Style TargetType="{x:Type ListBoxItem}" x:Key="LBIS">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
</Style>
</Window.Resources>
<ListBox ItemContainerStyle="{StaticResource LBIS}"/>
Both snippets open nicely in Blend 2 on a machine without the SP1 beta. As we need Blend 2 and do not rely on anything SP1-specific, I decided to uninstall SP1 beta. And here comes the problem – it is “mission impossible”. I have spent half of the last night trying to get rid of it, all in vain. I have tried everything, including Automated cleanup tool to remove the .NET Framework by Aaron Stebner (which by the way managed to completely remove .NET 3.5 – nice job, Aaron!!!). But the result is the same – Blend 2 is irreparably broken. I cannot even reinstall it as installer complains about “Unknown product…” and I cannot do anything about that – cleaning registry, monitoring installer’s activities, etc. did not help. Visual Studio 2008 is broken too now, but that is another story.
Microsoft guys know that Blend 2 is not really compatible with SP1 Beta of .NET 3.5, and recommend waiting for the release version of SP1. On the other hand, Blend 2.5 March CTP Refresh seems to work fine in this scenario.
I have to reinstall Windows now, which is not a problem per se, as I was planning it for some time now anyway, but one would expect that this kind of basic/primitive errors would not exist in beta product – we are not talking about an “advanced” scenario in this case.
