gpt4 book ai didi

c# - 在代码后面更改 Canvas.Left 属性?

转载 作者:IT王子 更新时间:2023-10-29 03:36:43 26 4
gpt4 key购买 nike

我的 XAML 中有一个矩形,我想在后面的代码中更改它的 Canvas.Left 属性:

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

有谁知道这样做的语法是什么?

最佳答案

Canvas.SetLeft(theObject, 50)

关于c# - 在代码后面更改 Canvas.Left 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/541420/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com