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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With