WPF Grid Control

929Free 661 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);
        }
Developer technologies | Windows Presentation Foundation
0 comments No comments

Answer accepted by question author

Ken Tucker 5,866 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>

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.