Archive for the 'WPF' category

Vista from a developer’s point of view

September 9, 2006 6:05 pm

To me Windows Vista marks a great new milestone for software developers. Not just because Microsoft invested years of development into a new programming framework, but because that framework will be included out of the box. Until now, if you wanted to take advantage of the power of the .Net Framework (1.0, 1.1 and 2.0) you had to either include the installer for the framework or create some other magic to get it on the user’s system (asking the user to please, please download and install it first?)

With Vista, not only do you get the .Net Framework 2.0 (much improved over the previous versions) in the box, but also the amazingly powerful Windows Presentation Foundation (which is what I’ve worked with), Windows Communication Foundation and Windows Workflow Foundation (two pieces I know nothing about yet).

This will lower the barrier to entry for applications developed using these powerful tools to zero. As long as you’re writing your application for Vista you can be sure the basic requirements are there.

There will be issues with certain features of WPF (rendering in software vs. hardware, especially for 3D), but the framework helps you detect these issues and makes it possible to adapt your application to lower its “flashyness” (RenderCapability.Tier, remember this needs to be shifted down by 16 bits if you want to use 0, 1 and 2 as the human readable values).

To me Windows Presentation Foundation is the most important technology to come out of Microsoft for a long time. I’ve never written too much actual Win32 or even MFC/ATL UI code for client applications, but I’ve done a lot of HTML / CSS stuff and pure business object stuff (COM/ATL). More about that in my next post. I don’t want this to get too long.

 

.Net Framework 3.0 RC1 issue with RenderCapability.Tier on Windows XP

September 5, 2006 11:58 am

I discovered that

System.Windows.Media.RenderCapability.Tierreported a wrong tier (zero) after I upgraded my Windows XP dev box’s .Net Framework 3.0 installation to the RC1 release. My card used to be a tier two and I had just upgraded the drivers, too. I contacted Microsoft about it and they said this is a known issue with the RC1 release and that it will be fixed in the upcoming RTM release. The problem is only with this particular API and only happens on Windows XP. All the actual rendering is still done correctly based on the capabilities of the hardware. So the only problem is if your WPF application is built to behave differently based on the value of this API call.There is a workaround that has to do with changing the value type of a certain registry entry (the video memory size) from Binary to DWORD. I’ll point to more details once I get a URL from Microsoft to point to.

Update: Here’s the link to the official release notes for this problem:

http://msdn.microsoft.com/windowsvista/support/relnotes/netfxRc1/default.aspx#topic6 

Also, I need to correct my statement about this only happening on XP. That’s not entirely correct. It happens with XPDM drivers, which you can have on Vista as well. It’s just more likely that you have XPDM drivers on XP.

 

CompositionTarget.Rendering can be a CPU hog

August 23, 2006 9:12 pm

I ran into an issue where my WPF application would consume about 20% of CPU time just sitting idle on a Page. A question from Tim Sneath led me to investigate an aspect of the app that uses the CompositionTarget.Rendering callback to do some animations that can’t be done in other ways in WPF right now.

I had several UIElements that each had the Rendering event hooked up, and the code in the event handler would do next to nothing most of the time, since the animation only was kicked off on a mouse up event. I modified the code, so that the event hookup doesn’t happen until the mouse up event comes in, and also so that an unhook happens when the animation is finished. This promptly took down the CPU load to the typical intermittent 1-2%.

Remember to unhook those event handlers!

August 7, 2006 3:13 pm

I thought I’d make my first post not just a “hello out there”, but something that’s marginally useful to some people. 

If you’re writing a Windows Presentation Foundation app that has just a little bit of complexity to it, you may do things like hook up UI Elements to event handlers. This could be for navigation, reacting to data changes, timers etc.

An important thing to remember is to unhoook those event handlers when your UI Element is unloaded. Otherwise the event handler hangs on to the visual tree and the garbage collector will not let go of it. This results in memory consumption “problems”, which is a nice word for a “managed memory leak”.

So if you do something like this:

public MyElement()
{
  InitializeComponent();
  Loaded += new EventHandler(OnLoaded);
}

public void OnLoaded(object sender, EventArgs e)
{
  myTimer.Tick += new EventHandler(OnTick);
}

Don’t forget to also hook the Unloaded event and do this in it:

public void Unloaded(object sender, EventArgs e)
{
  myTimer.Tick -= new EventHandler(OnTick);
}