简体   繁体   中英

c# How can I expand an item within a ListView to occupy multiple lines?

Currently I have a ListView (using the Details View). I would like to implement the behaviour whereby when a user selects a single item (log entry) the log entry expands (from one line to multiple lines) to provide more detailed information about the error that occured.

My question is this: Is this possible? If so, is there a good resource that I can use to help me?

EDIT:

If I HAVE to use WPF, then I guess Ill use the ElementHost with the control. However, I have absolutely no idea as to how about designing/coding/using WPF components. Any suggestions?

Edit: sorry this is wpf

The trick I used to achieve the same thing was creating a trigger to show a secondary grid which is defaulted to collapsed.

Try this out:

    <ListBox ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                    </Grid.RowDefinitions>

                    <Grid Grid.Row="0" Height="20" >
                        <TextBlock Text="Not Selected"></TextBlock>
                    </Grid>
                    <Grid x:Name="selectedOnlyGrid" Grid.Row="1" Visibility="Collapsed">
                        <TextBlock Text="Selected"></TextBlock>
                    </Grid>

                </Grid>

                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}, AncestorLevel=1}, Path=IsSelected}" Value="True">
                        <Setter Property="Visibility" Value="Visible" TargetName="selectedOnlyGrid" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

Have a read through the post on CodeProject Here: Extended List Box

Should have all the info you need for it :)

One way to do this with a ListView is going to be to dynamically add a new ListViewItem for each extra row you want when the "parent" is selected. Similarly, you'll need to remove them when the selection changes to another item.

You'll also probably want to override the default up/down behaviour to skip over the child items.

这不是您问题的直接答案,但我认为在这种情况下,最好使用网格。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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