简体   繁体   English

使用水平滚动(wpf)将listview划分为列

[英]Dividing listview into columns, with horizontal scroll (wpf)

I have a list view that is divided into two columns. 我有一个分为两列的列表视图。 The problem is what happens if the information that comes into the list view is too long of a string. 问题是,如果进入列表视图的信息太长,则字符串会发生什么。

If I make a fixed width, it will cut some of it. 如果我设置固定宽度,它将裁切一些宽度。 If I make an automatic width, then the initial state of the listview columns will look bad. 如果我设置了自动宽度,则listview列的初始状态将看起来很糟。

Fixed Width: 固定宽度: 在此处输入图片说明 Automatic Width: 自动宽度: 在此处输入图片说明 Any ideas what can I do to solve this? 有什么想法可以解决吗?

relevant XAML: 相关的XAML:

<ListView Width="Auto" Height="Auto" Margin="10" Background="#092E3E" Foreground="White" ItemsSource="{Binding BackupEvents}" >
    <ListView.ItemContainerStyle>
        <Style TargetType="{x:Type ListViewItem}">
            ...
        </Style>
    </ListView.ItemContainerStyle>
    <ListView.View>
        <GridView AllowsColumnReorder="False">
            <GridView.ColumnHeaderContainerStyle>
                 ...
            </GridView.ColumnHeaderContainerStyle>

            <GridView.Columns>
                <GridViewColumn Width="200" Header="Time" DisplayMemberBinding="{Binding LVTime}"/>

                // auto or fixed?
                <GridViewColumn Width="Auto"/"520" Header="Details" DisplayMemberBinding="{Binding LVDetails}"/>
            </GridView.Columns>
        </GridView>
    </ListView.View>
</ListView>

The best solution I think would be if I could make the column size fixed, but the text/list-entries to wrap into multiple lines if needed. 我认为最好的解决方案是使列大小固定,但是如果需要,可以将文本/列表条目包装成多行。 But I'm not sure how to do that... 但是我不确定该怎么做...

您可以在一定宽度的数据后显示省略号

The best solution I think would be if I could make the column size fixed, but the text/list-entries to wrap into multiple lines if needed. 我认为最好的解决方案是使列大小固定,但是如果需要,可以将文本/列表条目包装成多行。 But I'm not sure how to do that... 但是我不确定该怎么做...

You could define an implicit TextBlock Style that sets the TextWrapping property of all TextBlocks in the GridView to Wrap : 您可以定义一个隐式TextBlock Style ,将GridView中所有TextBlocksTextWrapping属性设置为Wrap

<ListView Width="Auto" Height="Auto" Margin="10" Background="#092E3E" Foreground="White" ItemsSource="{Binding BackupEvents}" >
    <!-- HERE: -->
    <ListView.Resources>
        <Style TargetType="{x:Type ListViewItem}">
            <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
        </Style>
    </ListView.Resources>
    <ListView.ItemContainerStyle>
        <Style TargetType="{x:Type ListViewItem}">
            ...
        </Style>
    </ListView.ItemContainerStyle>
    <ListView.View>
        <GridView AllowsColumnReorder="False">
            <GridView.ColumnHeaderContainerStyle>
                ...
            </GridView.ColumnHeaderContainerStyle>

            <GridView.Columns>
                <GridViewColumn Width="200" Header="Time" DisplayMemberBinding="{Binding LVTime}"/>

                // auto or fixed?
                <GridViewColumn Width="Auto"/"520" Header="Details" DisplayMemberBinding="{Binding LVDetails}"/>
            </GridView.Columns>
        </GridView>
    </ListView.View>
</ListView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM