WPF ScrollViewer show border when ScrollBar is Visible

bindingscrollviewerwpfwpf-controls

I want to add a border to my ScrollViewer. The border should only be shown when the ScrollBar of the ScrollViewer is Visible (VerticalScrollBarVisibility set to "Auto")

Thank you!

Best Answer

You can do this using styles and triggers, like this:

<Border BorderBrush="Black">
    <Border.Style>
        <Style>
            <Setter Property="Border.Visibility" Value="Visible" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=theScrollViewer, Path=ComputedVerticalScrollBarVisibility}" Value="Collapsed">
                    <Setter Property="Border.Visibility" Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Border.Style>
    <ScrollViewer Name="theScrollViewer">
    </ScrollViewer>
</Border>
Related Topic