使用GetValue和SetValue来设置属性
发布日期:2021-07-18 18:19:07
浏览次数:2
分类:技术文章
本文共 1060 字,大约阅读时间需要 3 分钟。
GetValue和SetValue是在托管代码中直接获取或设置对象属性的一种方法,如下面例子:
<Rectangle x:Name="rect_MyRectangle" Width="100" Height="100" Fill="Blue"></Rectangle> <TextBlock x:Name="txb_MyText2" /> C#代码:public yufa2() { InitializeComponent();//利用GetValue和SetValue double 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://blog.csdn.net/iteye_3606/article/details/82173383 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月11日 17时22分51秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
树莓派硬件启动失败log记录查看方法
2019-04-27
树莓派使用心得
2019-04-27
树莓派实现无显示器远程登录
2019-04-27
Samba服务实现树莓派与Windows之间的文件共享
2019-04-27
wiringpi安装编译问题解决
2019-04-27
Windows上创建Emacs配置文件
2019-04-27
编写并运行第一个Lisp程序
2019-04-27
VS code中godoc命令不可用问题解决
2019-04-27
Emacs-103-使用spacemacs自带配置显示行号
2019-04-27
021_Excel的条件格式
2019-04-27
022_Excel空白值批量填充默认值
2019-04-27
023_emacs git-gutter+报错解决
2019-04-27
024_spacemacs支持org-pomodoro的声音提示
2019-04-27
025_everything搜索使用体验
2019-04-27
026_好用的windows小工具clover
2019-04-27
027-Mac触摸板实现窗口移动
2019-04-27
028_AUTOSAR RTE学习笔记-1
2019-04-27
029_AUTOSAR VFB学习笔记-2
2019-04-27
030_AUTOSAR软件组件学习笔记
2019-04-27
031_AUTOSAR学习笔记_BSW
2019-04-27