How does TwoWay BindingMode work in an XMLDataProvider?

When TwoWay BindingMode is used, the XMLDataProvider writes the data to the ‘in – memory’ XML file and it does not write to the file in your hard disk. You have to perform your own serialization to write the data updated to the XML file in the hard disk.

What is the use of the RelativeSource property ?

The ‘RelativeSource’ property of the Binding class is used to bind the data from an element by it’s relationship to the source element. RelativeSource is also a markup extension of type RelativeSource. The following are some of the ways that RelativeSource can be used. 1. When the source element is equal to the target element, [C#] {Binding RelativeSource={RelativeSource Self}} 2. When the source element is equal to the target element’s TemplatedParent, [C#] {Binding RelativeSource={RelativeSource TemplatedParent}} 3. When the source element is equal to the closest parent of a given type, [C#] {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=Orientation} 4. When the source element is equal to the nth closest parent of a given type, [C#] {Binding RelativeSource={RelativeSource FindAncestor,AncestorLevel=1, AncestorType={x:Type Window}}, Path=Title} 5. When the source element is equal to the previous data item in a data – bound collection. [C#] {Binding RelativeSource={RelativeSource PreviousData}}

How can I determine whether a Freezable Is Frozen?

This example shows how to determine whether a Freezable object is frozen. If you try to modify a frozen Freezable object, it throws an ’Invalid Operation’ Exception. To avoid throwing this exception, use the ‘IsFrozen’ property of the Freezable object to determine whether it is frozen. [C#] Button myButton = new Button(); SolidColorBrush myBrush = new SolidColorBrush(Colors.Yellow); if (myBrush.CanFreeze) { // Makes the brush unmodifiable. myBrush.Freeze(); } myButton.Background = myBrush; if (myBrush.IsFrozen) // Evaluates to true. { // If the brush is frozen, create a clone and // modify the clone. SolidColorBrush myBrushClone = myBrush.Clone(); myBrushClone.Color = Colors.Red; myButton.Background = myBrushClone; } else { // If the brush is not frozen, // it can be modified directly. myBrush.Color = Colors.Red;

What is a Freezable?

A Freezable is a special type of object that has two states: ’unfrozen’ and ’frozen’. When unfrozen, a Freezable appears to behave like any other object, and it can no longer be modified. It also provides a changed event to notify observers of any modifications to the object. it improves performance, because it no longer needs to spend resources on change notifications. A frozen Freezable can also be shared across threads, while an unfrozen Freezable cannot be shared across threads. The Freezable class makes it easier to use certain graphics system objects and can help improve application performance. To freeze a Freezable object declared in markup, you can use the PresentationOptions ‘Freeze’ attribute. In the following example, a ’SolidColorBrush’ is declared as a page resource and frozen. It is then used to set the background of a button. [XAML] <Page xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:PresentationOptions='http://schemas.microsoft.com/winfx/2006/xaml/presentation/options' xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' mc:Ignorable='PresentationOptions'> <Page.Resources> <!-- This resource is frozen. --> <SolidColorBrush x:Key='MyBrush' PresentationOptions:Freeze='True' Color='Red' /> </Page.Resources> <StackPanel> <Button Content='A Button' Background='{StaticResource MyBrush}'> </Button> </StackPanel> </Page>

How to get the default template of a control programmatically ?

To get the Style for any given WPF control, get the control instance and use the ‘XAMLWriter’ class for writing the XAML related information. [C#] System.Windows.Controls.TextBox t = new System.Windows.Controls.TextBox(); StringBuilder sb = new StringBuilder(); using (TextWriter writer = new StringWriter(sb)) { System.Windows.Markup.XamlWriter.Save(t.Template, writer); }