Jason94
Jason94

Reputation: 13620

How can I move a button in code in a grid?

In my XAML I've set up a grid and placed some buttons. One button for instance is placed in row 1, column 1. Given a event, I would like to move that button to column 0, and set the rowspan to 2.

How can I do that with C# in the code behind?

Upvotes: 1

Views: 286

Answers (1)

Victor Hurdugaci
Victor Hurdugaci

Reputation: 28425

Assuming btn is your button, add the following code in the event handler for your event:

btn.SetValue(Grid.ColumnProperty, 0)
btn.SetValue(Grid.RowSpan, 2)

More info: http://msdn.microsoft.com/en-us/library/system.windows.controls.grid_attachedproperties(v=vs.95).aspx

Upvotes: 2

Related Questions