top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are Attached Properties in XAML?

+1 vote
228 views
What are Attached Properties in XAML?
posted Jun 7, 2016 by Latha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

The Attached Properties in XAML are the properties which can be used by other classes. A simple example of the attached properties is the Grid.Row property in the Stack Panel which defines where in the grid, the stack panel will be displayed in the Grid.

<Grid x:Name="LayoutRoot" Background="Transparent">
 <Grid.RowDefinitions>
  <RowDefinition Height="Auto" />
  <RowDefinition Height="*" />
 </Grid.RowDefinitions>
 <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
 </StackPanel>
</Grid>
answer Jun 7, 2016 by Shivaranjini
0 votes

Attached properties are a XAML concept, whereas dependency properties are a WPF concept. Because WPF attached properties are dependency properties, they support dependency property concepts such as property metadata, and default values from that property metadata.

An attached property is a concept defined by Extensible Application Markup Language (XAML). An attached property is intended to be used as a type of global property that is settable on any object. In Windows Presentation Foundation (WPF), attached properties are typically defined as a specialized form of dependency property that does not have the conventional property "wrapper"

Why Use Attached Properties

One purpose of an attached property is to allow different child elements to specify unique values for a property that is actually defined in a parent element. A specific application of this scenario is having child elements inform the parent element of how they are to be presented in the user interface (UI). One example is the DockPanel.Dock property. The DockPanel.Dock property is created as an attached property because it is designed to be set on elements that are contained within a DockPanel, rather than on DockPanel itself. The DockPanel class defines the static DependencyProperty field named DockProperty, and then provides the GetDock and SetDock methods as public accessors for the attached property.

Attached Properties Overview

.NET Framework 4 Other Versions
An attached property is a concept defined by Extensible Application Markup Language (XAML). An attached property is intended to be used as a type of global property that is settable on any object. In Windows Presentation Foundation (WPF), attached properties are typically defined as a specialized form of dependency property that does not have the conventional property "wrapper".
This topic contains the following sections.

Why Use Attached Properties

One purpose of an attached property is to allow different child elements to specify unique values for a property that is actually defined in a parent element. A specific application of this scenario is having child elements inform the parent element of how they are to be presented in the user interface (UI). One example is the DockPanel.Dock property. The DockPanel.Dock property is created as an attached property because it is designed to be set on elements that are contained within a DockPanel, rather than on DockPanel itself. The DockPanel class defines the static DependencyProperty field named DockProperty, and then provides the GetDock and SetDock methods as public accessors for the attached property.
Attached Properties in XAML
In XAML, you set attached properties by using the syntax AttachedPropertyProvider.PropertyName
The following is an example of how you can set DockPanel.Dock in XAML:
XAML

  <DockPanel>
  <CheckBox DockPanel.Dock="Top">Hello</CheckBox>
  </DockPanel>

Note that the usage is somewhat similar to a static property; you always reference the type DockPanel that owns and registers the attached property, rather than referring to any instance specified by name.
Also, because an attached property in XAML is an attribute that you set in markup, only the set operation has any relevance. You cannot directly get a property in XAML, although there are some indirect mechanisms for comparing values, such as triggers in styles

Attached Property Implementation in WPF

In Windows Presentation Foundation (WPF), most of the attached properties that exist on WPF types are implemented as dependency properties. Attached properties are a XAML concept, whereas dependency properties are a WPF concept. Because WPF attached properties are dependency properties, they support dependency property concepts such as property metadata, and default values from that property metadata.

answer Jun 7, 2016 by Jdk
Similar Questions
+1 vote

I need to know the XAML binding Properties and its description it will used for identify how to use binding in windows phone application??

...