C#: Escape Double-quote within a String
Posted by Tim Valentine in General on March 21, 2012
Problem
When you need to add a double-quote character to a string, you will run into a problem. Double-quotes are the delimiters for the beginning and end of a string, so placing a double-quote within a string will confuse the compiler and it will give you an exception.
Solution
C#: Escape Curly Braces within Formatted String
Posted by Tim Valentine in General on March 21, 2012
Problem
When passing in a formatted string as an argument to a method such as Console.WriteLine, String.Format, etc., curly braces have a special meaning. They are used as a placeholder for a variable. Therefore when you want to add a curly brace within the formatted string, but you don’t want it to be interpreted as a placeholder for a variable, you have a problem.
Solution
WPF: IsSynchronizedWithCurrentItem and ICollectionView Cancel Bug
Posted by Tim Valentine in Bug Patches, Controls, WPF 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.
Solution
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.
Solution
WPF: DataGrid Select-all-button Styling
Posted by Tim Valentine in Controls, Customization, WPF on January 4, 2011
Problem
The SelectAll button on Microsoft’s DataGrid control cannot be styled without a workaround. 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.
Solution
WPF Window – Disable Minimize and Maximize Buttons Through Attached Properties From XAML
Posted by Tim Valentine in 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