WPF Grid Control

929Free 281 Reputation points
2020-07-07T15:53:15.16+00:00

I want the grid control to automatically display the vertical scroll bar. Now it's all crowded together.How can I rewrite it?
Here is my code.....

XAML:
<Grid Name="TimeGrid" HorizontalAlignment="Left" ShowGridLines="False" Height="332" Margin="10,44,0,0" VerticalAlignment="Top" Width="772">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>

c#:
for (int i = 0; i < 100; i++)
{
RowDefinition obj = new RowDefinition();
obj.MaxHeight = 50;

            TimeGrid.RowDefinitions.Add(obj);

            Button btn_Click = new Button();

            btn_Click.Name = "Btn_1";
            btn_Click.Content = "Btn1";

            TimeGrid.Children.Add(btn_Click);

            btn_Click.SetValue(Grid.RowProperty, i);
            btn_Click.SetValue(Grid.ColumnProperty, 0);
        }
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ken Tucker 5,846 Reputation points
    2020-07-07T16:49:49.373+00:00

    Put the grid in a ScrollViewer. Do not set the Height on the timeGrid

       <ScrollViewer>
       <Grid Name="TimeGrid" HorizontalAlignment="Left" ShowGridLines="False"  Margin="10,44,0,0" VerticalAlignment="Top" Width="772">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
               <ColumnDefinition/>
               <ColumnDefinition/>
               <ColumnDefinition/>
               <ColumnDefinition/>
          </Grid.ColumnDefinitions>
      </Grid>
    </ScrollViewer>
    

0 additional answers

Sort by: Most helpful