I have a ScrollViewer, it scrolls vertically only, and shows the vertical scroll bar if it needs to only:
<ScrollViewer x:Name="sv" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
I also have a Label, which I only want to show if the ScrollViewer's vertical scroll bar is showing:
<Label Background="DarkBlue" Height="60" Width="70">
<Label.Style>
<Style TargetType="Label">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ComputedVerticalScrollBarVisibility.Visibility, ElementName=sv}" Value="Hidden">
<Setter Property="Visibility" Value="Hidden"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
This does not seem to work. I have searched for a solution, which normally I find quite quickly hence this being my first post. Any suggestions on how to get this working? I would prefer a xaml only solution but could be convinced to use converters and what-not.
First ComputedVerticalScrollBarVisibility
property is of type Visibility
.
So, you have to bind with ComputedVerticalScrollBarVisibility property only and not with ComputedVerticalScrollBarVisibility.Visibility.
Second, Value
will be Collapsed
and not Hidden
Update trigger to this:
<DataTrigger Binding="{Binding ComputedVerticalScrollBarVisibility,
ElementName=sv}" Value="Collapsed">
<Setter Property="Visibility" Value="Hidden"/>
</DataTrigger>
The simplest way is probably to bind your label's visibility directly to the scrollbar's computed visibility:
<Label Background="DarkBlue" Height="60" Width="70"
Visibility="{Binding ComputedVerticalScrollBarVisibility, ElementName=sv}" />
This way the label is only visible when the scrollbar is visible. Your example uses Hidden
and not Collapsed
. If you want to only hide the label and not collapse it you can use a converter for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With