在后面的代码中更改Canvas.Left属性? [英] Change Canvas.Left property in code behind?
本文介绍了在后面的代码中更改Canvas.Left属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的XAML中有一个矩形,想要更改其 Canvas.Left
属性的代码如下:
I have a rectangle in my XAML and want to change its Canvas.Left
property in code behind:
<UserControl x:Class="Second90.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300" KeyDown="txt_KeyDown">
<Canvas>
<Rectangle
Name="theObject"
Canvas.Top="20"
Canvas.Left="20"
Width="10"
Height="10"
Fill="Gray"/>
</Canvas>
</UserControl>
但这不起作用:
private void txt_KeyDown(object sender, KeyEventArgs e)
{
theObject.Canvas.Left = 50;
}
有人知道这样做的语法吗?
Does anyone know what the syntax is to do this?
推荐答案
Canvas.SetLeft(theObject, 50)
这篇关于在后面的代码中更改Canvas.Left属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文