WPF Tip: Working with ContentPresenter

September 26, 2010

When creating control templates, there is often a need to place an arbitrary content (of type object) in some location. Usually this is identified by a Content property (such as from ContentControl), but sometimes it’s some other property. The ContentPresenter class allows placing such arbitrary content that follows a few rules: 1. If the value is a string, render it as a TextBlock. 2. If the value is of a a UIElement derived type – render it as is. 3. Otherwise, if a ContentTemplate property exists and not null, use it. Otherwise, render it as a...
tags: , , ,
no comments

How To Be a Cool C++ Programmer / Developer

September 13, 2010

A few weeks ago I blogged about how to be a cool C# programmer. if you are a C++ programmer, you can be cool, too. The next C++ standard, dubbed C++0x promises many enhancements and cool abilities, but in this post I’ll stick with the current C++ standard. Here are some ways of being a cool C++ programmer (in no particular order): 1. Zeroing out a structure and setting its first field in one swoop One of the common needs in a native Windows applications is setting up structures in preparation for calling some API function. Most...
tags: , , ,
one comment

WPF Auto Size ComboBox, Improved

September 7, 2010

I’ve blogged about the problem of an auto sized ComboBox. I proposed a solution that seemed to work well enough, but it appears it did not work correctly if the SelectedItem or SelectedIndex properties were used with a Binding expression. Here’s an improved version that takes both situations into account: public class ComboBoxEx : ComboBox {    private int _selected;    Binding _indexBinding, _itemBinding;    object _selectedItem;      public override void OnApplyTemplate() {       base.OnApplyTemplate();...
tags: , , ,
no comments

How to Annoy Your Boss (or get yourself fired)

If you want to make your boss a bit crazy, here’s what you can do: First, get him away from his computer. You can explain you need to run some connectivity test or configure some important service for the sake of the project. Once he’s out of the way, you can proceed: 1. Install the Debugging Tools For Windows package (if you don’t have it already). You can get the latest version from the Windows SDK installation, but any previous version will do. We’ll need the Global Flags utility from that package. 2. Run gflags.exe (Start->Programs->Debugging...