Fixing IsSynchronizedWithCurrentItem and ICollectionView Cancel Bug with an Attached Property
Posted by Tim Valentine in WPF, Control Customization on November 7, 2011
Problem
As some of you may have noticed while working with a Selector-derived control and an ICollectionView, there is a bug with the IsSynchronizedWithCurrentItem property of Selector. IsSynchronizedWithCurrentItem is provided by Selector to support the ability to keep its SelectedItem in-sync with the CurrentItem of its ItemSource’s ICollectionView. IsSynchronizedWithCurrentItem works perfectly except for one specific case: when the CurrentChanging event of ICollectionView is handled and the item change is cancelled.
In this case the Selector does not respect the cancel and it gets out-of-sync with the ICollectionView. I’d imagine this bug exists because the Selector class was likely implemented before ICollectionView, and Selector was not updated to match the addition. Whatever happened though the bug does exist in WPF 4.0 and can be very problematic. Luckily, with attached properties at our disposable we can work up an easy fix.
VSTO COM Exception 0x800A01A8
Posted by Tim Valentine in VSTO on August 20, 2011
Problem
COM exceptions that give you just a HRESULT to describe an exception are terrible. During some VSTO development for Outlook 2007, I kept getting a COM exception with an HRESULT of 0x800A01A8, and eventually I found the reason why I was receiving the exception. I though I’d share since little information is available on this particular exception.
Style Microsoft’s DataGrid SelectAll Button using Attached Properties
Posted by Tim Valentine in Control Customization, WPF on January 4, 2011
Introduction
The SelectAll button on Microsoft’s DataGrid control can not be styled without some in-depth tricks. This is a direct result of there being no SelectAllButtonTemplate property on the control. To get around this issue we’ll make our own property using attached properties. This way we can have nice, clean, MVVM-compliant code and XAML-markup, while still getting what we want.
WPF Window – Disable Minimize and Maximize Buttons Through Attached Properties From XAML
Posted by Tim Valentine in Control Customization, WPF on April 19, 2010
Overview
Yesterday I worked up a static helper class that encapsulates the functionality to disable/enable/toggle the minimize and maximize buttons on a standard WPF window. This morning I updated that code to fix some bugs that I overlooked. Finally just not long ago, I updated the code with a new static class called WindowCustomizer, which allows this same functionality through the use of attached properties straight from XAML-markup. The advantage here is that this is now a full MVVM-compliant solution.
Read the rest of this entry »
Dynamic Code/Class Generation (Update)
Posted by Tim Valentine in General on March 18, 2010
Overview
Back not to long ago, I released a post dealing with the dynamic generation of classes at run-time. Since then I have applied the concepts shown in that post in my real-world projects. As expected of any new code, I have found several bugs and inconveniences with the original code from that post. This time around I have an updated CodeGenerationHelper class, a DynamicFactory class, and an actual example of how to use the generated objects. The download-able version of the sample can be obtained through this link: http://thrash505.webs.com/DynamicCodeGeneration.zip
C# CodeGenerationHelper – Dynamic Classes – Create Class From Hashtable at Run-time
Posted by Tim Valentine in General on February 4, 2010
UPDATE
This post has been depreciated, for an updated version please visit: http://thrash505.wordpress.com/2010/03/18/dynamic-codeclass-generation-update/
Overview
Back a few months ago I had a class that needed (or so I thought) to be generated at run-time. The need arose from WPF controls only working with Properties, not fields, and more specifically ones that implemented INotifyPropertyChanged. (or dependency properties, but I typically save those for custom controls) After some research I created a simple straightforward helper class, CodeGenerationHelper, that would create a dynamic class at run-time from a hashtable. From a hashtable because my solution was working with data received through XML-RPC in the from of an extended hastable implementation. (XmlRpcStruct)