Use of XAML, Property and Attribute

Original link: http://www.cnblogs.com/ycat/archive/2008/03/19/1113434.html

For Control, the property is set in XAML syntax, there are two, one is the Attribute XML element (element), the other element is Proptery

E.g

1. Set the button's XML element Attribute Content property and Background Properties

1 < Button  Content ="Hello World"  Background ="Blue"   />
2

2. XML elements disposed above button properties Proptery

1 < Button >
2      < Button.Content >
3         Hello World
4      </ Button.Content >
5       
6      < Button.Background >
7         Blue
8      </ Button.Background >
9 </ Button >

3.Content is C # ContentPropertyAttribute had so defined in XAML can be used directly as the value of XML elements appear

< Button  Background ="Blue" >
    Hello World
</ Button >

 4. Proptery XML elements form the set for Control Style

 1 < Button  Content ="Hello World" >
 2      < Button.Resources >
 3          < Style  x:Key ="ButtonStyler"  TargetType =" {x:Type Button} " >
 4      < Setter  Property ="Background" >
 5        < Setter.Value >
 6          < RadialGradientBrush >
 7            < GradientBrush.GradientStops >
 8              < GradientStopCollection >
 9                        < GradientStop  Color ="black"
10                             Offset ="0"   />
11                        < GradientStop  Color ="black"
12                             Offset ="1"   />
13                          </ GradientStopCollection >
14                       </ GradientBrush.GradientStops >
15                  </ RadialGradientBrush >
16             </ Setter.Value >
17          </ Setter >     
18      </ Button.Resources >
19
20      < Button.Style >
21          < StaticResource >
22              < StaticResource.ResourceKey >
23                   ButtonStyler
24              </ StaticResource.ResourceKey >
25          </ StaticResource >
26      </ Button.Style >
27 </ Button >

 

 

Reproduced in: https: //www.cnblogs.com/ycat/archive/2008/03/19/1113434.html

Guess you like

Origin blog.csdn.net/weixin_30673611/article/details/94798928