0

我尝试在窗口上做一个列列表,当我使用 *.

<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>

问题是 Wrappanel 内容的宽度和高度取决于它的正确内容,而不是窗口大小。

我希望你能帮助我。

谢谢。

4

3 回答 3

0

非常感谢你帮助我。

我结合了您的答案,并与其他一些搜索一起解决了这个问题,如下所示。

<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>

再一次:谢谢!

于 2013-09-20T17:12:18.617 回答
0

尝试这个:

<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}}">
于 2013-09-19T18:45:10.163 回答
0

我不知道你为什么要在这里使用 wrappanel,但是如果你想让你的listviewitem内容拉伸到列表视图的宽度,那么你可以在ListView.ItemContainerStyle下面输入:

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

并将 itemtemplate 设置为:

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

这会拉伸你的物品

于 2013-09-20T09:02:52.330 回答