What is XAML?

XAML is an extensible markup language based on XML. XAML can be thought of as a declarative script for creating .NET 3.0 UI. It is particularly used in WPF as a user interface markup language to define UI elements, data binding, eventing and other features. It is also used in Windows Workflow Foundation (WF), in which the workflows themselves can be defined in XAML code.

What is WPF?

Windows Presentation Foundation (WPF) is the presentation subsystem feature of the .NET Framework 3.0. It is pre-installed in as a part of Windows Vista, It is also available for installation on Windows XP SP2 and Windows Server 2003. It supports the rich User Experiences (UX) that have been made possible by advances in hardware and technology since the GDI based UI architecture was initially designed in the 1980’s. Also refer to the separate section on XAML in this FAQ

How can I create a ProgressBar and use an animation to simulate the progress of an operation ?

This example creates a ProgressBar and uses an ’animation’ to simulate the progress of an operation. [XAML] <StatusBar Name='sbar' VerticalAlignment='Bottom' Background='Beige' > <StatusBarItem> <TextBlock>Downloading File</TextBlock> </StatusBarItem> <StatusBarItem> <ProgressBar Width='100' Height='20' Name='progressBar1'> <ProgressBar.Triggers> <EventTrigger RoutedEvent='ProgressBar.Loaded'> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName='progressBar1' Storyboard.TargetProperty='Value' From='0' To='100' Duration='0:0:5' /> </Storyboard> </BeginStoryboard> </EventTrigger> </ProgressBar.Triggers> </ProgressBar> </StatusBarItem> <StatusBarItem> <Separator/> </StatusBarItem> <StatusBarItem> <TextBlock>Online</TextBlock> </StatusBarItem> <StatusBarItem HorizontalAlignment='Right'> <Image Source='images\help.bmp' Width='16' Height='16'/> </StatusBarItem> </StatusBar>

What is the use of x:code ?

x:Code is a directive element defined in XAML. An x:Code directive element can contain inline programming code. The code that is defined inline can interact with the XAML on the same page. The following example illustrates inline C# code. Notice that the code is inside the x:Code element and that the code must be surrounded by <CDATA[…]]> to escape the contents for XML, so that an XAML processor (interpreting either the XAML schema or the WPF schema) will not try to interpret the contents literally as XML. [XAML] <Page xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Class='MyNamespace.MyCanvasCodeInline' > <Button Name='button1' Click='Clicked'>Click Me!</Button> <x:Code><![CDATA[ void Clicked(object sender, RoutedEventArgs e) { button1.Content = 'Hello World'; } ]]></x:Code> </Page>

What are Attached Properties and how to register it?

An ‘attached’ property is a concept defined by Extensible Application Markup Language (XAML). It is intended to be used as a type of global property that can be set on any object. In Windows Presentation Foundation (WPF), attached properties are typically defined as specialized forms of dependency properties that do not have the conventional ‘wrapper’ property. This example shows how to ’register’ an attached property and provide public accessors so that you can use the property in both Extensible Application Markup Language (XAML) and code. Attached properties are a syntax concept defined by Extensible Application Markup Language (XAML). Most of the attached properties for WPF types are also implemented as dependency properties. You can use dependency properties on any ’DependencyObject’ types. [C#] public static readonly DependencyProperty IsBubbleSourceProperty = DependencyProperty.RegisterAttached( 'IsBubbleSource', typeof(Boolean), typeof(AquariumObject), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender) ); public static void SetIsBubbleSource(UIElement element, Boolean value) { element.SetValue(IsBubbleSourceProperty, value); } public static Boolean GetIsBubbleSource(UIElement element) { return (Boolean)element.GetValue(IsBubbleSourceProperty); }