How do I debug my data-binding setup?

XAML code is not debuggable and any bindings that are setup in XAML or in code-behind are normally very tricky to debug as well. This article provides some ideas on how to setup debugging to get error information and such when binding happens: How can I debug WPF bindings

How do I programatically interact with template generated elements?

Getting hold of an element in a ControlTemplate is very easy, as this article explains: How do I programmatically interact with template-generated elements? Part I Sample code: Grid gridInTemplate = (Grid)myButton1.Template.FindName(‘grid’, myButton1); But, if want to get hold of an item in a DataTemplate (which gets applied for each item in the ItemsControl), then there is more code involved as explained here: How do I programmatically interact with template-generated elements? Part II Sample Code: // Note that the ListBox must have // IsSynchronizedWithCurrentItem set to True for this to work ListBoxItem myListBoxItem = (ListBoxItem)(myListBox.ItemContainerGenerator.ContainerFromItem(myListBox.Items.CurrentItem)); ContentPresenter myContentPresenter = FindVisualChild(myListBoxItem); DataTemplate myDataTemplate = myContentPresenter.ContentTemplate; TextBlock myTextBlock = (TextBlock)myDataTemplate.FindName(‘textBlock’, myContentPresenter);

How can I create a ControlTemplate for a HeaderedItemsControl ?

ControlTemplate can be created for a HeaderedItemsControl as follows. [XAML] <!–Define a control template for a HeaderedItemsControl–> <Style TargetType=’HeaderedItemsControl’> <Setter Property=’Template’> <Setter.Value> <ControlTemplate TargetType='{x:Type HeaderedItemsControl}’> <StackPanel> <Grid> <Rectangle Fill='{TemplateBinding Background}’/> <ContentPresenter ContentSource=’Header’/> </Grid> <Grid> <Rectangle Stroke='{TemplateBinding BorderBrush}’/> <ItemsPresenter Margin=’2,0,0,0’/> </Grid> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> … <HeaderedItemsControl xmlns:sys=’clr-namespace:System;assembly=mscorlib’ Header=’My colors’ Background=’SteelBlue’ BorderBrush=’DarkSlateBlue’> <sys:String>Red</sys:String> <sys:String>Yellow</sys:String> <sys:String>Blue</sys:String> <sys:String>Green</sys:String> </HeaderedItemsControl>