views:

657

answers:

3

Hi guys.
I'm gonna insert a Separator in a ListView in WPF , something like this :
image

I've used the following XAML code, but it dosn't work !

<ListView ItemsSource="{Binding ListViewItemsCollections}">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Name" Width="200" DisplayMemberBinding="{Binding GridViewColumnName}"/>
            <GridViewColumn Header="Tags" Width="200" DisplayMemberBinding="{Binding GridViewColumnTags}"/>
            <GridViewColumn Header="Location" Width="400" DisplayMemberBinding="{Binding GridViewColumnLication}"/>
        </GridView>
    </ListView.View>
    <Separator />
</ListView>

Could you please guide me ? Thanks.

+1  A: 

Try putting the separator in the collection of items you are binding to. In the above code you are stting the items via the itemsSource binding and then setting the items by adding a seperator to the content. Add the seperator to the collection of items and you will see a blank row in your grid. you might have to style the separator accordingly. (but it will give you a row you cant click on)

Aran Mulholland
In the collection of items, I can just put strings , not an object like a Separator !
Mohammad
well then you need to either make the collection be of type object, or wrap the collection in another collection that allows object, or use a composite collection (a collection of items and collections) so you could have a collection of items before separator than your separator then your next collection of strings.
Aran Mulholland
I really don't think that is necessary. Separator belongs to the presentation layer, not to the logic/model layers.
Piotr Justyna
I would like a solution to this. "Separator belongs to the presentation layer, not to the logic/model layers." - is exactly what i think. I have not had success templating a business object as a seperator
Aran Mulholland
A: 

Mohammad,

have you tried to apply a DataTemplate to your ListView?

Piotr Justyna
Yes, I used a CellTemplate to insert an Image to the ListView.Do you know any samples for Separators ?
Mohammad
Actually I do :) Please follow the instructions from my latest answer to your question.
Piotr Justyna
+1  A: 

Mohammad,

I believe inserting a separator (or a control which mimics one) is far more simple than you think :)

First of all, please take a look on how DataTemplate should be applied to a ListBox/ListView. You can find it here. Secondly, you have to decide how you're going to mimic a Separator. You can find 2 excellent examples here and here. Please keep me informed if your task is done :)

Piotr Justyna
Thanks my friend, I'll see them.
Mohammad
That's not a problem at all :)Please rate my answer and mark it as accepted if it was helpful.
Piotr Justyna
I read carefully all of links, But I didn't realize how I should add a separator to a ListView that I bound it's ItemsSource !
Mohammad
Why would you like to bind your separator to ItemSrouce? Are you sure you're doing everything as it's shown? If you still have no solution, please post your code or provide me with some further details so I can solve your problem.
Piotr Justyna