Friday 31 May 2013

About x:Prefix

Posted by Rahul at 03:50
In the previous root element example, the prefix x: was used to map the XAML namespace http://schemas.microsoft.com/winfx/2006/xaml, which is the dedicated XAML namespace that supports XAML language constructs. This x: prefix is used for mapping this XAML namespace in the templates for projects. The XAML namespace for the XAML language contain several programming constructs that you will use very frequently in your XAML. The following is a listing of the most common x: prefix programming constructs you will use: 

x:Key: Sets a unique key for each resource in a ResourceDictionary (or similar dictionary concepts in other frameworks)

Example
<Grid>
    <Grid.Resources>
        <Style x:Name="StyleName" x:Key="StyleKey" />
    </Grid.Resources>
    <Button Style="{StaticResource StyleKey}" />
</Grid>

x:Class: Specifies the CLR namespace and class name for the class that provides code-behind for a XAML page. You must have such a class tos support code-behind per the WPF programming model, and therefore you almost always see x: mapped, even if there are no resources.

x:Name: Specifies a run-time object name for the instance that exists in run-time code after an object element is processed. In general, you will frequently use a WPF-defined equivalent property for x:Name. Such properties map specifically to a CLR backing property and are thus more convenient for application programming, where you frequently use run time code to find the named elements from initialized XAML. The most common such property is FrameworkElement.Name. You might still use x:Name when the equivalent WPF framework-level Name property is not supported in a particular type. This occurs in certain animation scenarios.

Example
<Button x:Name="okButton">OK</Button>

x:Static: Enables a reference that returns a static value that is not otherwise a XAML-compatible property. 

Example
<SolidColorBrush Color="{x:Static SystemColors.ControlColor}" />

x:Type: Constructs a Type reference based on a type name. This is used to specify attributes that take Type, such as Style.TargetType, although frequently the property has native string-to-Type conversion in such a way that the x:Type markup extension usage is optional.

Example
<Style TargetType="{x:Type Button}">
    ...
</Style>

Reference 




If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to know WPF | Template by Blogger Widgets

Home | About | Top