3

I'm trying to use the grid row / column definitions in my wpf application. At the moment, I need to implement a list view inside a GroupBox. Here I need to ignore the column definitions i set in the top in the view.

Row and column definitions:

        <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="260" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="250" />
        <ColumnDefinition Width="20" />
        <ColumnDefinition Width="180" />
        <ColumnDefinition Width="20" />
        <ColumnDefinition Width="180" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

Here you see I have a rowDefinition with a height of 260. This should contain my list view. The problem is that it's inside the columns I have made and therefore it won't take all space. Is there somehow a setting so that this row will ignore the columns I have set? I still want the columns to be used for the other rows.

Here you see a picture of how it looks:

enter image description here

Hope someone can help, good day.

Taterhead
  • 5,763
  • 4
  • 31
  • 40
Mandersen
  • 805
  • 3
  • 14
  • 22

3 Answers3

10

Just use attached property Grid.ColumnSpan :

<ListView Grid.ColumnSpan="6"/>

It will extend your ListView for 6 columns.

Simple advice about your UI:

I suggest you to create you resizable XAML, not static. I mean it is not good:

<Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="260" />
    <RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="250" />
    <ColumnDefinition Width="20" />
    <ColumnDefinition Width="180" />
    <ColumnDefinition Width="20" />
    <ColumnDefinition Width="180" />
    <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

However, it is better:

<Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="3*" />
    <RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="0.5*" />
    <ColumnDefinition Width="2*" />
    <ColumnDefinition Width="0.5*" />
    <ColumnDefinition Width="2*" />
    <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

It gives resizable UI(XAML) at any display.

StepUp
  • 36,391
  • 15
  • 88
  • 148
1

You can set Grid.ColumnSpan="6" on your listview. It will expand in the row.

<ListView Grid.ColumnSpan="6"/>
Nitin
  • 18,344
  • 2
  • 36
  • 53
1

depends on how you want to display the listview.

you can add another grid, just to be safe, that you will want to add something later on that row.

<Grid grid.Row="6" Grid.Column="0" Grid.ColumnSpan="6">
  <ListView> </ListView>
</Grid>
alexmac
  • 19,087
  • 7
  • 58
  • 69
Grand Julivan
  • 264
  • 2
  • 13