使用GetValue和SetValue来设置属性

 2023-09-16 阅读 24 评论 0

摘要:GetValue和SetValue是在托管代码中直接获取或设置对象属性的一种方法,如下面例子: <Rectangle x:Name="rect_MyRectangle" Width="100" Height="100" Fill="Blue"></Rectangle><TextBlock x:N

GetValue和SetValue是在托管代码中直接获取或设置对象属性的一种方法,如下面例子:

  <Rectangle x:Name="rect_MyRectangle"  Width="100" Height="100" Fill="Blue"></Rectangle><TextBlock x:Name="txb_MyText2"  />


C#代码:

 
public yufa2(){InitializeComponent();//利用GetValue和SetValuedouble left = 400;double top = 30;double radius = 10;string width;string height;//设置矩形的位置rect_MyRectangle.SetValue(Canvas.LeftProperty, left);rect_MyRectangle.SetValue(Canvas.TopProperty, top);//设置矩形的圆角度rect_MyRectangle.SetValue(Rectangle.RadiusXProperty, radius);rect_MyRectangle.SetValue(Rectangle.RadiusYProperty, radius);//获取矩形的宽和高width = rect_MyRectangle.GetValue(Rectangle.WidthProperty).ToString();height = rect_MyRectangle.GetValue(Rectangle.HeightProperty).ToString();//输出文本txb_MyText2.Text = "矩形的宽是:" + width + " 高是:" + height;txb_MyText2.SetValue(Canvas.LeftProperty, 400.00);}

 
 

设置存档属性?运行如图:


版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/66129.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息