以编程方式更改Canvas上的StackPanel位置 [英] Change StackPanel location on a Canvas programmatically

查看:61
本文介绍了以编程方式更改Canvas上的StackPanel位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在画布上有堆栈面板

堆栈面板有

 <Canvas x:Name="MyCanvas">
            <Slider Template="{StaticResource simpleSlider}"  x:Name="seekBar" Thumb.DragStarted="seekBar_DragStarted" Thumb.DragCompleted="seekBar_DragCompleted" Canvas.Left="347" Canvas.Top="746" Width="900" Height="2" />
            <Rectangle Height="5" />

       <StackPanel Canvas.Left="200" Canvas.Right = "100">
       </StackPanel>
 </Canvas>

在运行时,我需要更改对象在StackPanel中的位置。

At runtime I need to change the location of the objects within the StackPanel.

即seekBar.Canvas.Left = 50

Ie seekBar.Canvas.Left = 50

推荐答案

Canvas.Left是一个附加依赖项属性的示例。 C#的语法为:

The "Canvas.Left" is an example of attached dependency property. The syntax for the C# is:

Canvas.SetLeft(myStackPanel, 50);

myStackPanel是必须在xaml中使用x.Name分配的任何自定义名称。

Where myStackPanel is any custom name you must assign using x.Name in the xaml.

这篇关于以编程方式更改Canvas上的StackPanel位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆