Listbox Separator in WPF and Omission of Final Separator

只愿长相守 提交于 2019-12-03 13:50:16

You can try to put Separator at the top of each item. With that you don't have unwanted Separator after the last item.

Then use DataTrigger with {RelativeSource PreviousData} binding to hide separator at the top of the first item :

<StackPanel>
    <Separator>
        <Separator.Style>
            <Style TargetType="Separator">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Separator.Style>
    </Separator>
    <StackPanel Orientation="Horizontal">
        <Button Name="ThirdPartyInstallButton" Content="Install" Click="InstallThirdPartyUpdatesButton_Click" Margin="5,5,0,0" Height="25"></Button>
        <Button Name="ThirdPartyPostoneButton" Content="Postpone" Click ="PostponeThirdPartyUpdatesButton_Click" Margin="5,5,0,0" Height="25"></Button>
        <Grid>
            .........
            .........
        </Grid>
    </StackPanel>
</StackPanel>

UPDATE :

I can't tell for sure what causes the separator not stretching accross listbox width. Maybe try to set listboxitem's HorizontalContentAlignment to Stretch :

<ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    </Style>
</ListBox.ItemContainerStyle>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!