Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Trigger when vertical scrollbar thumb height is less than some value

$
0
0

I have custom scrollbar where thumb (moving part) has image in its center. I need to collapse image when thumb height is less than image height. It seems that there is no way to trigger on current height of thumb (i tried height and actualheight properties, both are wrong).

<local:CutoffConverter x:Key="ThumbHeightConverter" Cutoff="34" />

<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Name="ThumbBorder" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Border.Style>
                            <Style TargetType="{x:Type Border}">
                                <Setter Property="Background" Value="{StaticResource VScrollBarThumbNormalBrush}" />
                            </Style>
                        </Border.Style>
                        <Grid>
                            <Image Name="ThumbImage" Stretch="Fill" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" >
                                <Image.Style>
                                    <Style TargetType="{x:Type Image}">
                                        <Setter Property="Width" Value="26" />
                                        <Setter Property="Height" Value="34" />
                                        <Setter Property="MinHeight" Value="34" />
                                        <Setter Property="MaxHeight" Value="34" />
                                        <Setter Property="Source" Value="{StaticResource VScrollBarThumbNormal}" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Path=ActualHeight,
                                                RelativeSource={RelativeSource Mode=FindAncestor,
                                                AncestorType={x:Type Thumb}},
                                                Converter={StaticResource ThumbHeightConverter}}" Value="True">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ThumbImage" Property="Source" Value="{StaticResource VScrollBarThumbHover}" />
                            <Setter TargetName="ThumbBorder" Property="Background" Value="{StaticResource VScrollBarThumbHoverBrush}" />
                        </Trigger>
                        <Trigger Property="IsDragging" Value="True">
                            <Setter TargetName="ThumbImage" Property="Source" Value="{StaticResource VScrollBarThumbPressed}" />
                            <Setter TargetName="ThumbBorder" Property="Background" Value="{StaticResource VScrollBarThumbPressedBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


Converter code:

    public class CutoffConverter : IValueConverter
    {
        public int Cutoff { get; set; }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is double))
                return false;
            if (Double.IsNaN((double)value))
                return false;
            return ((int)((double)value)) < Cutoff;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>