zoukankan      html  css  js  c++  java
  • 使用GetValue和SetValue来设置属性

    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);
            }

     
    
    

    运行如图:


  • 相关阅读:
    进制间转换的理论和实现不同
    操作DOM
    浏览器对象
    浏览器
    面向对象编程——class继承
    面向对象编程——原型继承
    js面向对象编程——创建对象
    JS面向对象编程
    js的JSON
    js标准对象——Date
  • 原文地址:https://www.cnblogs.com/raphael5200/p/5114911.html
Copyright © 2011-2022 走看看