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>

How do I add custom controls to an application using Microsoft Expression Blend ?

Expression Blend supports custom controls to be added to a WPF application. To add a custom control to a WPF application the following steps have to be performed. 1. Select Add Reference from Project Menu. 2. Browse and select the dll that contains the definition of the custom control. 3. Select Asset library from toolbox. 4. Select custom controls tab and select the necessary control from the list.

How to write some XML into IsolatedStorage?

[C#] Stream mystream = new IsolatedStorageFileStream( storeFileName, FileMode.Create, isoStorage ); if( null != mystream ) { XmlTextWriter xmlwriter = new XmlTextWriter(mystream, Encoding.UTF8); this.WriteDateToWriter( xmlwriter ); xmlwriter.Flush(); stream.Close(); }