StefanHa
StefanHa

Reputation: 727

Items in ItemControls size automatically

I have the next problem. I have a ItemsControl defined with xaml.

 <Grid>
     <Grid.RowDefinitions>
         <RowDefinition Height="50" />
         <RowDefinition Height="50" />
     </Grid.RowDefinitions>
     <Button Grid.Row="0" ></Button>
     <ItemsControl Grid.Row="1" x:Name="ItemsControl"></ItemsControl>
 </Grid>

In the codebehind I have this ItemsControl be filled with buttons.

public Window1()
        {
            InitializeComponent();
            var list = new List<Button>();
            list.Add(new Button() { Name = "btn1", Visibility = Visibility.Visible});
            list.Add(new Button() { Name = "btn2", Visibility = Visibility.Collapsed});
            list.Add(new Button() { Name = "btn3", Visibility = Visibility.Collapsed});
            ItemsControl.ItemsSource = list;
        }

Now when the buttons are rendered the height is very small. I want the buttons to be rendered at the max height of the ItemsControl. Is there a way?

Upvotes: 1

Views: 152

Answers (1)

Tom
Tom

Reputation: 3374

try this answer out, I had a go and it worked nicely :D

Stretching controls to fill ItemsControl

Don't forget <RowDefinition Height="*" />

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="50" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Button Grid.Row="0" ></Button>
    <ItemsControl Grid.Row="1" x:Name="ItemsControl">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Columns="1" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</Grid>

Upvotes: 1

Related Questions