views:

1753

answers:

4

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?

A: 

Not a direct answer to your question, but I think you're better off with a grid in this case.

axk
Unfortunatly, I require the column headdings that are present within the ListView when using the Details view
TK
+2  A: 

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

Should have all the info you need for it :)

Pondidum
+1  A: 

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.

Nigel Hawkins
+1  A: 

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>
buggs
Im sorry but my understanding of both XAML and WPF is completely non-existant at this point. Could you possibly explain what this code does above? Thanks.
TK
Sure ...<Grid x:Name="selectedOnlyGrid" Grid.Row="1" Visibility="Collapsed">Is a grid that is hidden (collapsed) by default.Then there is a data trigger, bound to the IsSelected of it's parent ListItem, so when it is 'selected' it becomes visible.Hope this helps.
buggs