2017-07-04 47 views
0

我有一個水平的堆疊面板,我在其中添加項目。我想在每個項目名稱下面添加一個分隔符,而不是位於名稱的右側,並且該分隔符應該跨越整個頁面。這2個問題都沒有幫我到現在:How to add a vertical Separator?How can a separator be added between items in an ItemsControlWPF如何把分隔符放在水平堆棧面板中的每個項目下面

enter image description here

視圖代碼是:

<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> 
+0

你有沒有嘗試過沒有內部'StackPanel'?只需一個'StackPanel'並將所有三個元素放在裏面? –

+0

@MightyBadaboom我剛試過,也更新了問題。但問題仍然存在,意味着分隔符是垂直的,並且位於項目名稱的右側。 – Iason

回答

0

使第一StackPanel中垂直,並把內容控制和內標籤一個水平的堆疊面板。這樣的事情:

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

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