Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the Grid.Row and Grid.Column of the control from code behind in wpf

Tags:

c#

wpf

I have the control placed in DataGrid like this:

<Label Name="lblDescription" HorizontalAlignment="Left" Margin="0,5,0,0" Grid.Row="2" Grid.Column="2" /> <TextBox  Name="txtDescription" HorizontalAlignment="Left" Width="200" Margin="0,5,0,0" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" AcceptsReturn="True" Grid.RowSpan="2" Grid.Row="2" Grid.Column="3" /> 

How can I change the Grid.Row and Grid.Column of the control in code behind?

like image 521
Kuntady Nithesh Avatar asked Jan 20 '12 03:01

Kuntady Nithesh


People also ask

How to use Grid in WPF c#?

First Method: By typing XAML CodeRowDefinitions property and a ColumnDefinition Element for each column inside the Grid. ColumnDefinitions property. By default, GridLines are invisible. For showing the GridLines, set the ShowGridLines property of the Grid to True.

How Grid works in XAML?

The Grid element in XAML represents a WPF Grid control. The following code snippet creates a Grid control, sets it width and foreground color and make sure grid lines are visible. The ColumnDefinitions property is used to add columns and the RowDefinitions property is used to add rows to a Grid.

What is Grid C#?

Grid uses the GridLength object to define the sizing characteristics of a RowDefinition or ColumnDefinition. For a definition of each unit type, see GridUnitType. If a child element is added to a column within a Grid, and the column has its Width property set to Auto , the child will be measured without restrictions.


1 Answers

There is also a static method to do this (analogous to using the property in code to set a non-attached property rather than using the DP there).

Grid.SetRow(txtDescription, 1); 

You may find this more readable.

like image 66
Random832 Avatar answered Oct 08 '22 06:10

Random832