0

I try to do a list of columns on a window and I want to have the same result than in a Grid when I use the *.

<ListView ItemsSource="{Binding UcColumns}" 
              HorizontalContentAlignment="Stretch"
              VerticalAlignment="Stretch"                  
              ScrollViewer.VerticalScrollBarVisibility="Disabled"
              ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>                    
                <WrapPanel IsItemsHost="True" Margin="0"                               
                           Orientation="Horizontal" Background="WhiteSmoke"
                           >


                </WrapPanel>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>

    </ListView>

The problem is that the Wrappanel content width and height is depending of it proper content but not of the window size.

I hope you can help me.

Thx.

chriga
  • 798
  • 2
  • 12
  • 29

3 Answers3

0

Try this:

<WrapPanel IsItemsHost="True" Margin="0" Orientation="Horizontal" Background="WhiteSmoke"
           Width="{Binding ActualWidth,
                RelativeSource={RelativeSource AncestorType={x:Type ScrollContentPresenter}, Mode=FindAncestor}}"

Height="{Binding ActualHeight,
                RelativeSource={RelativeSource AncestorType={x:Type ScrollContentPresenter}, Mode=FindAncestor}}">
0

I don't know why you want wrappanel here, but if you want your listviewitem content to stretch to the listview width then you can put the ListView.ItemContainerStyle like below:

        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            </Style>
        </ListView.ItemContainerStyle>

And set the itemtemplate like:

<ListBox.ItemTemplate>
     <DataTemplate>
        <Grid HorizontalAlignment="Stretch">
         <local:MyuserControl HorizontalAlignment="Stretch"/>
        </Grid>
      </DataTemplate>
</ListBox.ItemTemplate>

This will stretch your items

Nitin
  • 18,344
  • 2
  • 36
  • 53
0

Thanks a lot for helping me.

I combinate your answer and with some other search I solve this problem as write under.

<ListView ItemsSource="{Binding UcColumns}" 
              HorizontalContentAlignment="Stretch"
              VerticalAlignment="Stretch"                  
              ScrollViewer.VerticalScrollBarVisibility="Disabled"
              ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            </Style>
        </ListView.ItemContainerStyle>

        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"></StackPanel>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>

        <ListView.ItemTemplate>
            <DataTemplate >
                <uc:UC_Column HorizontalAlignment="Stretch" VerticalAlignment="Stretch"                                      
                                  Width="{Binding ActualWidth,
                                        Converter={cv:DivideConverter},
                                        ConverterParameter=3,
                                        RelativeSource={RelativeSource AncestorType={x:Type ScrollContentPresenter}, Mode=FindAncestor}}"
                                  Height="{Binding ActualHeight,
                                        RelativeSource={RelativeSource AncestorType={x:Type ScrollContentPresenter}, Mode=FindAncestor}}"/>

            </DataTemplate>
        </ListView.ItemTemplate>

    </ListView>

One time again : thank you !