开发者

How to change the property of component in wpf?

开发者 https://www.devze.com 2023-04-09 19:59 出处:网络
This is a very simple case I want to click on the button, then change the itself position the visual studio prompt me that is a public property, and the type is double. Why I cannot change the value

This is a very simple case

I want to click on the button, then change the itself position

the visual studio prompt me that is a public property, and the type is double. Why I cannot change the value? And it does not provide any method let me change the top property, so how I can change the property?

<Button C开发者_如何学Goontent="Button" Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="0,0,0,0" Name="Button1" VerticalAlignment="Top" Width="75" Grid.Row="1" />
MsgBox(Button1.Margin.Top)
Button1.Margin.Top = 10


You can't set each margin individually, but you can set the button margin to a new thickness and hardcode 10 as the top margin while leaving the other values untouched:

Button1.Margin = New Thickness(Button1.Margin.Left, 10, Button1.Margin.Right, Button1.Margin.Bottom)


If you want to move the button around don't use Margin, it's not made for that intent.

Instead, place your button in a Canvas, then you can set Canvas.Top/Bottom/Left/Right to move your button around (they are attached properties).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号