Iason
Iason

Reputation: 249

WPF how to put separator below each item in horizontal stackpanel

I've got a horizontal stackpanel on which I add items. I would like to add a separator below each project name, rather than it being to the right of the name, and that separator should span the whole page. These 2 questions haven't helped me up to now: How to add a vertical Separator? How can a separator be added between items in an ItemsControl

enter image description here

The View code is:

<ListView ItemsSource="{Binding Projects}" Margin="49,188,54,0">
  <ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
      <EventSetter Event="PreviewMouseLeftButtonDown" Handler="EventSetter_OnHandler"/>
    </Style>
  </ListView.ItemContainerStyle>
  <ListView.ItemTemplate>
    <DataTemplate>
      <StackPanel Orientation="Horizontal">
        <ContentControl Content="{StaticResource  Appbar_Suitcase}"/>
        <Label Content="{Binding Name}"/>
        <Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}"/>
      </StackPanel>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

Upvotes: 0

Views: 1213

Answers (1)

DotNetDoctor
DotNetDoctor

Reputation: 36

make the first stackpanel vertical and put the content control and the label inside of a horizontal stackpanel. something like this:

<StackPanel>
    <StackPanel Orientation="Horizontal">
        <ContentControl  Content="{StaticResource  Appbar_Suitcase}" />
        <Label Content="{Binding Name}"/>
    </StackPanel>

    <Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
</StackPanel>

Upvotes: 2

Related Questions