Wpf 对象属性赋值---属性标签



 

 

 1。给一个stop按钮赋予一个stop的图形。

如图:


 

 

 代码如下:

    

ExpandedBlockStart.gif View Code
 1  < Window x:Class = " wpfTest.MainWindow "
 2          xmlns = " http://schemas.microsoft.com/winfx/2006/xaml/presentation "
 3          xmlns:x = " http://schemas.microsoft.com/winfx/2006/xaml "
 4          xmlns:local = " clr-namespace:wpfTest "
 5          Title = " MainWindow "  Height = " 350 "  Width = " 525 " >
 6       < Window.Resources >
 7           < local:Human x:Key = " wtqHum "  name = " wtq "  child = " thisismyname "   ></ local:Human >
 8 
 9       </ Window.Resources >
10    
11       < Grid >
12          
13           < Button Width = " 100 "  Height = " 30 " >
14               < Button.Content >
15                   < Rectangle Width = " 15 "  Height = " 15 "  Stroke = " Blue "  Fill = " Red " ></ Rectangle >
16               </ Button.Content >
17              
18           </ Button >
19       </ Grid >
20  </ Window >

 

 2、给一个矩形区域使用渐变

如图:

 

 

 

 

 代码如下:

ExpandedBlockStart.gif View Code
 1  < Grid >
 2           < Rectangle Width = " 300 "  Height = " 200 " >
 3               < Rectangle.Fill >
 4                   < LinearGradientBrush >
 5                       < LinearGradientBrush.StartPoint >
 6                           < Point X = " 0 "  Y = " 0 " />       
 7                       </ LinearGradientBrush.StartPoint >
 8                       < LinearGradientBrush.EndPoint >
 9                           < Point X = " 1 "  Y = " 0 " ></ Point >
10                       </ LinearGradientBrush.EndPoint >
11                       < LinearGradientBrush.GradientStops >
12                           < GradientStopCollection >
13                               < GradientStop Offset = " 0.1 "  Color = " Red " />
14                               < GradientStop Offset = " 0.4 "  Color = " GreenYellow " />
15                               < GradientStop Offset = " 0.9 "  Color = " Blue " />
16                               < GradientStop Offset = " 1 "  Color = " Azure " />
17                           </ GradientStopCollection >
18                       </ LinearGradientBrush.GradientStops >
19                      
20                   </ LinearGradientBrush >
21 
22               </ Rectangle.Fill >
23              
24              
25           </ Rectangle >
26          
27       </ Grid >

 

上面例子代码的改进。

如下:

ExpandedBlockStart.gif View Code
 1  < Window x:Class = " wpf.Window1 "
 2          xmlns = " http://schemas.microsoft.com/winfx/2006/xaml/presentation "
 3          xmlns:x = " http://schemas.microsoft.com/winfx/2006/xaml "
 4          Title = " Window1 "  Height = " 300 "  Width = " 300 " >
 5       < Grid >
 6           < Rectangle Width = " 300 "  Height = " 200 " >
 7               < Rectangle.Fill >
 8                   < LinearGradientBrush StartPoint = " 0,0 "  EndPoint = " 0,1 " >
 9                       < LinearGradientBrush.GradientStops >
10                           < GradientStop Offset = " 0.1 "  Color = " Yellow " />
11                           < GradientStop Offset = " 0.5 "  Color = " blue " />
12                       </ LinearGradientBrush.GradientStops >
13                   </ LinearGradientBrush >
14               </ Rectangle.Fill >
15              
16           </ Rectangle >
17       </ Grid >
18  </ Window >

 

 原则。1,能使用attribute=value对属性赋值,尽量使用这种方式。

          2,若使用默认值的属性,则可以不用写出来,

              比如:

             <LinearGradientBrush StartPoint="0,0" EndPoint="1,1"> 默认的StartPoint为“”0,0“ 默认的EndPoint为”1,1“则可以不写出来。如下:
 
              <LinearGradientBrush>

 


 

 

 

参考:属性标签

转载于:https://www.cnblogs.com/85538649/archive/2011/08/18/WpfAttribute.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值