I want to adjust the width or visibility of a Border or Margin that is placed above a separate ListBox if the vertical scroll bar of the ListBox is collapsed.
I am trying something like this, but cannot figure out how to get to the ListBox ScrollViewer. Obviously, the Path in the DataTrigger is not correct.
<Border Width={Binding Source={x:Static SystemParameters.ScrollWidth}}">
<Border.Style>
<Style>
<Setter Property="Border.Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=listBox,
Path=***ScrollViewer.ComputedVerticalScrollBarVisibility***}"
Value="Collapsed">
<Setter Property="Border.Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
<ListBox Name="listBox" ItemsSource="{Binding MyItems}"/>
Is there a way to get to that ListBox property? If not, is there a better way to solve this problem?
Thanks much!
The workaround of wrapping the ListBox in another ScrollViewer allows an all-XAML solution at the expense of a redundant ScrollViewer control (see comment in the question). In the end, my team-mate decided to go with a code-behind solution as follows.
Here are the relevant attributes for the ListBox that has the ScrollViewer we need to access.
Here is the code-behind to expose the scroll viewer for use by external controls.
Here are the extension methods used:
And finally, the scroll viewer can be accessed in another part of the XAML.