Change Canvas.Left property in code behind?

后端 未结 3 2044
梦如初夏
梦如初夏 2020-12-08 00:13

I have a rectangle in my XAML and want to change its Canvas.Left property in code behind:



        
相关标签:
3条回答
  • 2020-12-08 00:14
    Canvas.SetLeft(theObject, 50)
    

    0 讨论(0)
  • 2020-12-08 00:26

    As we are changing the property of the 'object', it would be better to use method suggedte by JaredPar:

    theObject.SetValue(Canvas.LeftProperty, 50d);
    
    0 讨论(0)
  • 2020-12-08 00:36

    Try this

    theObject.SetValue(Canvas.LeftProperty, 50d);
    

    There is a group of methods on DependencyObject (base of most WPF classes) which allow the common access to all dependency properties. They are

    • SetValue
    • GetValue
    • ClearValue

    Edit Updated the set to use a double literal since the target type is a double.

    0 讨论(0)
提交回复
热议问题