Change Canvas.Left property in code behind?

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

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



        
3条回答
  •  猫巷女王i
    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.

提交回复
热议问题