mview popups use AutoHideScrollBar to prevent scrollbars from covering data

This commit is contained in:
John Colvin committed 2019-11-25 13:18:49 -06:00
1 parent 8508e275b8
commit b46d3637cb
6 files changed
+739 -141

No files matched your search

@@ -138,8 +138,11 @@ namespace mbts.ui.spark {
}
}
void _show_popup(object content, object header) =>
_show_popup(content, header, new AuxiliaryDataResources());
void _show_popup(object content, object header) {
var resources = new AuxiliaryDataResources();
resources.MergedDictionaries.Add(new AutoHideScrollbarResources());
_show_popup(content, header, resources);
}
void _show_popup(object content, object header, ResourceDictionary resources) {
var view = new HeaderedContentControl {
@@ -1,126 +1,136 @@
using mbts.ui.dpi;
using mbts.ui.extensions;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace mbts.ui.controls.adorners {
class DIYGridCellHoverAdorner : Adorner<ListBox>, IDisposable {
Brush _row_fill, _cell_fill;
Pen _row_stroke, _cell_stroke;
DIYGridRowsPresenter _rows_presenter;
ScrollViewer _scroll_viewer;
ScrollContentPresenter _scroll_content_backing;
DIYGrid _grid;
IDisposable _dispose;
DIYGrid.CellGeometry? _hover_cell;
AdornerHost _menu_host = null;
ActionMenu _menu => _menu_host.Child as ActionMenu;
#region RowFill
public static readonly DependencyProperty RowFillProperty =
WPFHelper.create_dp<Brush, DIYGridCellHoverAdorner>(
nameof(RowFill),
FrameworkPropertyMetadataOptions.AffectsRender,
(o, v) => o._row_fill = v,
FrozenBrushCache.get_brush(DIYGrid.DefaultSelectionHighlight));
public SolidColorBrush RowFill {
get => GetValue(RowFillProperty) as SolidColorBrush;
set => SetValue(RowFillProperty, value);
}
#endregion
#region RowStroke
public static readonly DependencyProperty RowStrokeProperty =
WPFHelper.create_dp<Pen, DIYGridCellHoverAdorner>(
nameof(RowStroke),
FrameworkPropertyMetadataOptions.AffectsRender,
(o, v) => o._row_stroke = v);
public Pen RowStroke {
get => GetValue(RowStrokeProperty) as Pen;
set => SetValue(RowStrokeProperty, value);
}
#endregion
#region CellFill
public static readonly DependencyProperty CellFillProperty =
WPFHelper.create_dp<Brush, DIYGridCellHoverAdorner>(
nameof(CellFill),
FrameworkPropertyMetadataOptions.AffectsRender,
(o, v) => o._cell_fill = v);
public SolidColorBrush CellFill {
get => GetValue(CellFillProperty) as SolidColorBrush;
set => SetValue(CellFillProperty, value);
}
#endregion
#region CellStroke
public static readonly DependencyProperty CellStrokeProperty =
WPFHelper.create_dp<Pen, DIYGridCellHoverAdorner>(
nameof(CellStroke),
FrameworkPropertyMetadataOptions.AffectsRender,
(o, v) => o._cell_stroke = v);
public Pen CellStroke {
get => GetValue(CellStrokeProperty) as Pen;
set => SetValue(CellStrokeProperty, value);
}
#endregion
public DIYGridCellHoverAdorner(DIYGridRowsPresenter adorned_element, ScrollViewer scroll_viewer)
: base(adorned_element) {
_row_fill = RowFill;
_row_stroke = RowStroke;
_cell_fill = CellFill;
_cell_stroke = CellStroke;
_scroll_viewer = scroll_viewer;
IsHitTestVisible = false;
_rows_presenter = adorned_element;
_grid = _rows_presenter.find_ancestor_of_type<DIYGrid>();
_dispose = Disposable.Create(
_grid.SubscribeMouseHoverCell().Subscribe(cell => {
_hover_cell = cell;
if (_hover_cell.HasValue) {
var (row, col) = _hover_cell.Value;
var row_tl = row.TranslatePoint(default, this);
}
InvalidateVisual();
}));
}
ScrollContentPresenter _scroll_content =>
_scroll_content_backing ?? (_scroll_content_backing = _scroll_viewer.descendants_of_type<ScrollContentPresenter>().FirstOrDefault());
protected override void OnRender(DrawingContext drawingContext) {
base.OnRender(drawingContext);
if (_hover_cell.HasValue) {
(var row, var cell) = _hover_cell.Value;
if (row != null) {
var row_tl = new Lazy<Point>(() => row.TranslatePoint(default, this));
if (_row_fill != null || _row_stroke != null) {
var row_rect = new Rect(row_tl.Value, row.RenderSize);
if (_scroll_content != null) {
var content_bounds = this.GetChildBounds(_scroll_content);
row_rect.Intersect(content_bounds);
}
drawingContext.DrawRectangle(_row_fill, _row_stroke, row_rect, true);
}
if (_cell_fill != null || _cell_stroke != null) {
var cell_rect = cell.to_visible_rect(row.ActualHeight, row_tl.Value.Y);
drawingContext.DrawRectangle(_cell_fill, _cell_stroke, cell_rect, true);
}
}
}
}
public void Dispose() =>
Disposable.dispose(ref _dispose);
}
}
using mbts.ui.dpi;
using mbts.ui.extensions;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
namespace mbts.ui.controls.adorners {
class DIYGridCellHoverAdorner : Adorner, IDisposable {
Brush _row_fill, _cell_fill;
Pen _row_stroke, _cell_stroke;
ScrollViewer _scroll_viewer;
ScrollContentPresenter _scroll_content;
DIYGrid _grid;
IDisposable _dispose;
DIYGrid.CellGeometry? _hover_cell;
AdornerHost _menu_host = null;
ActionMenu _menu => _menu_host.Child as ActionMenu;
#region RowFill
public static readonly DependencyProperty RowFillProperty =
WPFHelper.create_dp<Brush, DIYGridCellHoverAdorner>(
nameof(RowFill),
FrameworkPropertyMetadataOptions.AffectsRender,
(o, v) => o._row_fill = v,
FrozenBrushCache.get_brush(DIYGrid.DefaultSelectionHighlight));
public SolidColorBrush RowFill {
get => GetValue(RowFillProperty) as SolidColorBrush;
set => SetValue(RowFillProperty, value);
}
#endregion
#region RowStroke
public static readonly DependencyProperty RowStrokeProperty =
WPFHelper.create_dp<Pen, DIYGridCellHoverAdorner>(
nameof(RowStroke),
FrameworkPropertyMetadataOptions.AffectsRender,
(o, v) => o._row_stroke = v);
public Pen RowStroke {
get => GetValue(RowStrokeProperty) as Pen;
set => SetValue(RowStrokeProperty, value);
}
#endregion
#region CellFill
public static readonly DependencyProperty CellFillProperty =
WPFHelper.create_dp<Brush, DIYGridCellHoverAdorner>(
nameof(CellFill),
FrameworkPropertyMetadataOptions.AffectsRender,
(o, v) => o._cell_fill = v);
public SolidColorBrush CellFill {
get => GetValue(CellFillProperty) as SolidColorBrush;
set => SetValue(CellFillProperty, value);
}
#endregion
#region CellStroke
public static readonly DependencyProperty CellStrokeProperty =
WPFHelper.create_dp<Pen, DIYGridCellHoverAdorner>(
nameof(CellStroke),
FrameworkPropertyMetadataOptions.AffectsRender,
(o, v) => o._cell_stroke = v);
public Pen CellStroke {
get => GetValue(CellStrokeProperty) as Pen;
set => SetValue(CellStrokeProperty, value);
}
#endregion
public DIYGridCellHoverAdorner(ListBox list_box, ScrollViewer scroll_viewer)
: this(list_box, scroll_viewer, list_box.descendants_of_type<ScrollContentPresenter>().FirstOrDefault()) { }
/// <summary>
/// Create an instance of the <see cref="DIYGridCellHoverAdorner"/> class.
/// </summary>
/// <param name="list_box"></param>
/// <param name="scroll_viewer"></param>
/// <param name="scroll_content">
/// The actual AdornedElement (the ScrollViewer may clip the ScrollContentPresenter, and the most prudent way to reflect such a clip is to use it as the actual AdornedElement).
/// </param>
public DIYGridCellHoverAdorner(ListBox list_box, ScrollViewer scroll_viewer, ScrollContentPresenter scroll_content)
: base(scroll_content) {
_row_fill = RowFill;
_row_stroke = RowStroke;
_cell_fill = CellFill;
_cell_stroke = CellStroke;
_scroll_viewer = scroll_viewer;
_scroll_content = scroll_content;
IsHitTestVisible = false;
// reflect AdornedElement's clip
IsClipEnabled = true;
_grid = list_box.find_ancestor_of_type<DIYGrid>();
_dispose = Disposable.Create(
_grid.SubscribeMouseHoverCell().Subscribe(cell => {
_hover_cell = cell;
if (_hover_cell.HasValue) {
var (row, col) = _hover_cell.Value;
var row_tl = row.TranslatePoint(default, this);
}
InvalidateVisual();
}));
}
protected override void OnRender(DrawingContext drawingContext) {
base.OnRender(drawingContext);
if (_hover_cell.HasValue) {
(var row, var cell) = _hover_cell.Value;
if (row != null) {
var row_tl = new Lazy<Point>(() => row.TranslatePoint(default, this));
if (_row_fill != null || _row_stroke != null) {
var row_rect = new Rect(row_tl.Value, row.RenderSize);
if (_scroll_content != null) {
var content_bounds = this.GetChildBounds(_scroll_content);
row_rect.Intersect(content_bounds);
}
drawingContext.DrawRectangle(_row_fill, _row_stroke, row_rect, true);
}
if (_cell_fill != null || _cell_stroke != null) {
var cell_rect = cell.to_visible_rect(row.ActualHeight, row_tl.Value.Y);
drawingContext.DrawRectangle(_cell_fill, _cell_stroke, cell_rect, true);
}
}
}
}
public void Dispose() =>
Disposable.dispose(ref _dispose);
}
}
@@ -8,13 +8,11 @@ using System.Windows.Documents;
using System.Windows.Media;
namespace mbts.ui.controls.adorners {
class RowSelectionAdorner : Adorner<ListBox>, IDisposable {
class RowSelectionAdorner : Adorner, IDisposable {
Brush _fill;
Pen _stroke;
DIYGridRowsPresenter _diy_rp;
ListBox _diy_rp;
ScrollViewer _diy_scroll;
ScrollContentPresenter _diy_scp;
List<IDisposable> _disposables = new List<IDisposable>();
#region Fill
@@ -45,15 +43,28 @@ namespace mbts.ui.controls.adorners {
}
#endregion
public RowSelectionAdorner(DIYGridRowsPresenter adorned_element, ScrollViewer scroll_viewer) : base(adorned_element) {
public RowSelectionAdorner(ListBox list_box, ScrollViewer scroll_viewer)
: this(list_box, scroll_viewer, list_box.descendants_of_type<ScrollContentPresenter>().FirstOrDefault()) { }
/// <summary>
/// Create an instance of the <see cref="RowSelectionAdorner"/> class.
/// </summary>
/// <param name="list_box"></param>
/// <param name="scroll_viewer"></param>
/// <param name="scroll_presenter">
/// The actual AdornedElement (the ScrollViewer may clip the ScrollContentPresenter, and the most prudent way to reflect such a clip is to use it as the actual AdornedElement).
/// </param>
public RowSelectionAdorner(ListBox list_box, ScrollViewer scroll_viewer, ScrollContentPresenter scroll_presenter)
: base(scroll_presenter) {
_fill = Fill;
_stroke = Stroke;
// we want our clicks to go through to the underlying grid
IsHitTestVisible = false;
// reflect the AdornedElement's clip
IsClipEnabled = true;
_diy_rp = adorned_element;
_diy_rp = list_box;
_diy_scroll = scroll_viewer;
_diy_scp = _diy_rp.descendants_of_type<ScrollContentPresenter>().empty_if_null().FirstOrDefault();
// We actually don't need mouse up/down or key up/down when we can just respond to selection changes
_disposables.Add(((System.Windows.Controls.Primitives.Selector)_diy_rp).SubscribeSelectionChanged((s, e) => InvalidateVisual()));
@@ -63,22 +74,22 @@ namespace mbts.ui.controls.adorners {
protected override void OnRender(DrawingContext drawingContext) {
base.OnRender(drawingContext);
if (AdornedElement is ListBox lb && lb.SelectedItems != null && lb.SelectedItems.Count > 0) {
foreach(var lbi in lb.SelectedItems) {
if (_diy_rp.SelectedItems != null && _diy_rp.SelectedItems.Count > 0) {
foreach(var lbi in _diy_rp.SelectedItems) {
if (_diy_rp.ItemContainerGenerator.ContainerFromItem(lbi) is FrameworkElement row && row.IsVisible) {
var top_left = lb.GetChildTopLeft(row);
var top_left = _diy_rp.GetChildTopLeft(row);
var top_is_within_bounds = top_left.Y >= 0;
// Note that the top of the row can still technically be visible but we wont show
// the adorner rectangle b/c the bottom of the row will be obscured by the scrollbar
var bottom_is_within_bounds = lb.GetChildBounds(row).BottomRight.Y <= _diy_scroll.ActualHeight;
var bottom_is_within_bounds = _diy_rp.GetChildBounds(row).BottomRight.Y <= _diy_scroll.ActualHeight;
if (top_is_within_bounds && bottom_is_within_bounds) {
// we use the scroll content presenter in the X point calculation instead of the row
// because of the OB which has a right side panel that takes up some space over
// row width
drawingContext.DrawRectangle(_fill,
_stroke,
new Rect(top_left, new Point(top_left.X + _diy_scp.ActualWidth, top_left.Y + row.ActualHeight)));
new Rect(top_left, new Point(top_left.X + AdornedElement.RenderSize.Width, top_left.Y + row.ActualHeight)));
}
}
}
@@ -0,0 +1,493 @@
<ResourceDictionary
x:Class="mbts.ui.controls.AutoHideScrollbarResources"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="clr-namespace:mbts.ui"
xmlns:c="clr-namespace:mbts.ui.controls"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
>
<sys:Double x:Key="ScrollBarCollapsedWidth">5</sys:Double>
<sys:Double x:Key="ScrollBarCollapsedHeight">5</sys:Double>
<!--Thumb Colors-->
<Color x:Key="ThumbStaticColor">#FFCDCDCD</Color>
<Color x:Key="ThumbMouseOverColor">#FFA6A6A6</Color>
<Color x:Key="ThumbPressedColor">#FF606060</Color>
<!--Line Button Colors-->
<Color x:Key="LineButtonStaticBackgroundColor">#FFF0F0F0</Color>
<Color x:Key="LineButtonMouseOverBackgroundColor">#FFDADADA</Color>
<Color x:Key="LineButtonPressedBackgroundColor">#FF606060</Color>
<Color x:Key="LineButtonStaticForegroundColor">#FF606060</Color>
<Color x:Key="LineButtonMouseOverForegroundColor">#FF000000</Color>
<Color x:Key="LineButtonPressedForegroundColor">#FFFFFFFF</Color>
<Color x:Key="LineButtonDisabledForegroundColor">#FFBFBFBF</Color>
<!--Track-->
<Color x:Key="TrackStaticBackgroundColor">#FFF0F0F0</Color>
<sys:String x:Key="ArrowUpGeometry">
M0,4C0,4 0,6 0,6 0,6 3.5,2.5 3.5,2.5 3.5,2.5 7,6 7,6 7,6 7,4 7,4 7,4 3.5,0.5 3.5,0.5 3.5,0.5 0,4 0,4z
</sys:String>
<sys:String x:Key="ArrowDownGeometry">
M0,2.5C0,2.5 0,0.5 0,0.5 0,0.5 3.5,4 3.5,4 3.5,4 7,0.5 7,0.5 7,0.5 7,2.5 7,2.5 7,2.5 3.5,6 3.5,6 3.5,6 0,2.5 0,2.5z
</sys:String>
<Style x:Key="ScrollBarTrackThumb" TargetType="Thumb">
<Setter Property="Focusable" Value="False"/>
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Rectangle
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
Fill="{TemplateBinding Background}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="PageButton" TargetType="RepeatButton">
<!--<Setter Property="Background" Value="#FFF0F0F0"/>-->
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Rectangle
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
Fill="{TemplateBinding Background}"
/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="LineButton" TargetType="RepeatButton">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{StaticResource LineButtonStaticForegroundColor}"/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border
Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}"
>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="MouseStates">
<VisualState Name="Normal"/>
<VisualState Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" BeginTime="0" Duration="0" To="{StaticResource LineButtonMouseOverBackgroundColor}"/>
</Storyboard>
</VisualState>
<VisualState Name="Pressed">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" BeginTime="0" Duration="0" To="{StaticResource LineButtonPressedBackgroundColor}"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border.Background>
<SolidColorBrush Color="{StaticResource LineButtonStaticBackgroundColor}"/>
</Border.Background>
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{StaticResource LineButtonMouseOverForegroundColor}"/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{StaticResource LineButtonPressedForegroundColor}"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<ControlTemplate x:Key="HorizontalScrollBarTemplate" TargetType="ScrollBar">
<Grid
Background="Transparent"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
>
<u:StateManager.Groups>
<u:StateGroupsManager AttachToMembers="True">
<u:StateDefinitionCollection>
<u:MouseStateDefinition MouseSource="{Binding Group.Target, RelativeSource={RelativeSource Self}}"/>
</u:StateDefinitionCollection>
</u:StateGroupsManager>
</u:StateManager.Groups>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="MouseStates">
<VisualState Name="Normal">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="PART_Track" Storyboard.TargetProperty="Height" BeginTime="00:00:01" Duration="00:00:00.25" To="{StaticResource ScrollBarCollapsedHeight}"/>
<DoubleAnimation Storyboard.TargetName="PART_TrackBackground" Storyboard.TargetProperty="Opacity" BeginTime="00:00:01.75" Duration="00:00:00.20" To="0"/>
<!--Line Up-->
<DoubleAnimation Storyboard.TargetName="PART_LineLeftButton" Storyboard.TargetProperty="Height" BeginTime="00:00:01" Duration="00:00:00.25" To="{StaticResource ScrollBarCollapsedHeight}"/>
<DoubleAnimation Storyboard.TargetName="PART_LineLeftButton" Storyboard.TargetProperty="Opacity" BeginTime="00:00:01.75" Duration="00:00:00.20" To="0"/>
<!--Line Down-->
<DoubleAnimation Storyboard.TargetName="PART_LineRightButton" Storyboard.TargetProperty="Height" BeginTime="00:00:01" Duration="00:00:00.25" To="{StaticResource ScrollBarCollapsedHeight}"/>
<DoubleAnimation Storyboard.TargetName="PART_LineRightButton" Storyboard.TargetProperty="Opacity" BeginTime="00:00:01.75" Duration="00:00:00.20" To="0"/>
</Storyboard>
</VisualState>
<VisualState Name="MouseOver">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="PART_Track" Storyboard.TargetProperty="Height" BeginTime="0" Duration="00:00:00.15" To="{x:Static SystemParameters.HorizontalScrollBarHeight}"/>
<DoubleAnimation Storyboard.TargetName="PART_TrackBackground" Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0" To="1"/>
<!--Line Up-->
<DoubleAnimation Storyboard.TargetName="PART_LineLeftButton" Storyboard.TargetProperty="Opacity" BeginTime="00:00:00" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="PART_LineLeftButton" Storyboard.TargetProperty="Height" BeginTime="00:00:00" Duration="00:00:00.15" To="{x:Static SystemParameters.HorizontalScrollBarHeight}"/>
<!--Line Down-->
<DoubleAnimation Storyboard.TargetName="PART_LineRightButton" Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="PART_LineRightButton" Storyboard.TargetProperty="Height" BeginTime="0" Duration="00:00:00.15" To="{x:Static SystemParameters.HorizontalScrollBarHeight}"/>
</Storyboard>
</VisualState>
<VisualState Name="Pressed">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="PART_Track" Storyboard.TargetProperty="Height" BeginTime="0" Duration="0" To="{x:Static SystemParameters.HorizontalScrollBarHeight}"/>
<DoubleAnimation Storyboard.TargetName="PART_TrackBackground" Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0" To="1"/>
<!--Line Up-->
<DoubleAnimation Storyboard.TargetName="PART_LineLeftButton" Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="PART_LineLeftButton" Storyboard.TargetProperty="Height" BeginTime="0" Duration="00:00:00.15" To="{x:Static SystemParameters.HorizontalScrollBarHeight}"/>
<!--Line Down-->
<DoubleAnimation Storyboard.TargetName="PART_LineRightButton" Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="PART_LineRightButton" Storyboard.TargetProperty="Height" BeginTime="0" Duration="00:00:00.15" To="{x:Static SystemParameters.HorizontalScrollBarHeight}"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MaxWidth="{x:Static SystemParameters.HorizontalScrollBarButtonWidth}"/>
<ColumnDefinition Width="0.00001*"/>
<ColumnDefinition Width="*" MaxWidth="{x:Static SystemParameters.HorizontalScrollBarButtonWidth}"/>
</Grid.ColumnDefinitions>
<RepeatButton
x:Name="PART_LineLeftButton"
Command="{x:Static ScrollBar.LineLeftCommand}"
Focusable="False"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Opacity="0"
Height="{StaticResource ScrollBarCollapsedHeight}"
Style="{StaticResource LineButton}"
>
<Path
x:Name="ArrowUp"
Data="{Binding Source={StaticResource ArrowUpGeometry}}"
Fill="{Binding Parent.Foreground, RelativeSource={RelativeSource Self}}"
/>
</RepeatButton>
<Track
x:Name="PART_Track"
Grid.Column="1"
IsDirectionReversed="True"
Focusable="False"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Height="{StaticResource ScrollBarCollapsedHeight}"
>
<Track.Thumb>
<Thumb x:Name="Thumb" Style="{StaticResource ScrollBarTrackThumb}">
<u:StateManager.Groups>
<u:StateGroupsManager AttachToMembers="True">
<u:StateDefinitionCollection>
<u:MouseStateDefinition MouseSource="{Binding Group.Target, RelativeSource={RelativeSource Self}}"/>
</u:StateDefinitionCollection>
</u:StateGroupsManager>
</u:StateManager.Groups>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="MouseStates">
<VisualState Name="Normal"/>
<VisualState Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" BeginTime="0" Duration="0" To="{StaticResource ThumbMouseOverColor}"/>
</Storyboard>
</VisualState>
<VisualState Name="Pressed">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" BeginTime="0" Duration="0" To="{StaticResource ThumbPressedColor}"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Thumb.Background>
<SolidColorBrush Color="{StaticResource ThumbStaticColor}"/>
</Thumb.Background>
</Thumb>
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageRightCommand" Style="{StaticResource PageButton}"/>
</Track.IncreaseRepeatButton>
<Track.DecreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageLeftCommand" Style="{StaticResource PageButton}"/>
</Track.DecreaseRepeatButton>
</Track>
<Rectangle
x:Name="PART_TrackBackground"
Grid.Column="1"
Panel.ZIndex="-1"
Focusable="False"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
IsHitTestVisible="False"
Opacity="0"
Height="{Binding ActualHeight, ElementName=PART_Track}"
>
<Shape.Fill>
<SolidColorBrush Color="{StaticResource TrackStaticBackgroundColor}"/>
</Shape.Fill>
</Rectangle>
<RepeatButton
x:Name="PART_LineRightButton"
Grid.Column="2"
Command="{x:Static ScrollBar.LineRightCommand}"
Focusable="False"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Opacity="0"
Height="{StaticResource ScrollBarCollapsedHeight}"
Style="{StaticResource LineButton}"
>
<Path
x:Name="ArrowDown"
Data="{Binding Source={StaticResource ArrowDownGeometry}}"
Fill="{Binding Parent.Foreground, RelativeSource={RelativeSource Self}}"
/>
</RepeatButton>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Thumb" Property="Visibility" Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="VerticalScrollBarTemplate" TargetType="ScrollBar">
<Grid
Background="Transparent"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
>
<u:StateManager.Groups>
<u:StateGroupsManager AttachToMembers="True">
<u:StateDefinitionCollection>
<u:MouseStateDefinition MouseSource="{Binding Group.Target, RelativeSource={RelativeSource Self}}"/>
</u:StateDefinitionCollection>
</u:StateGroupsManager>
</u:StateManager.Groups>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="MouseStates">
<VisualState Name="Normal">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="PART_Track" Storyboard.TargetProperty="Width" BeginTime="00:00:01" Duration="00:00:00.25" To="{StaticResource ScrollBarCollapsedWidth}"/>
<DoubleAnimation Storyboard.TargetName="PART_TrackBackground" Storyboard.TargetProperty="Opacity" BeginTime="00:00:01.75" Duration="00:00:00.20" To="0"/>
<!--Line Up-->
<DoubleAnimation Storyboard.TargetName="PART_LineUpButton" Storyboard.TargetProperty="Width" BeginTime="00:00:01" Duration="00:00:00.25" To="{StaticResource ScrollBarCollapsedWidth}"/>
<DoubleAnimation Storyboard.TargetName="PART_LineUpButton" Storyboard.TargetProperty="Opacity" BeginTime="00:00:01.75" Duration="00:00:00.20" To="0"/>
<!--Line Down-->
<DoubleAnimation Storyboard.TargetName="PART_LineDownButton" Storyboard.TargetProperty="Width" BeginTime="00:00:01" Duration="00:00:00.25" To="{StaticResource ScrollBarCollapsedWidth}"/>
<DoubleAnimation Storyboard.TargetName="PART_LineDownButton" Storyboard.TargetProperty="Opacity" BeginTime="00:00:01.75" Duration="00:00:00.20" To="0"/>
</Storyboard>
</VisualState>
<VisualState Name="MouseOver">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="PART_Track" Storyboard.TargetProperty="Width" BeginTime="0" Duration="00:00:00.15" To="{x:Static SystemParameters.VerticalScrollBarWidth}"/>
<DoubleAnimation Storyboard.TargetName="PART_TrackBackground" Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0" To="1"/>
<!--Line Up-->
<DoubleAnimation Storyboard.TargetName="PART_LineUpButton" Storyboard.TargetProperty="Opacity" BeginTime="00:00:00" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="PART_LineUpButton" Storyboard.TargetProperty="Width" BeginTime="00:00:00" Duration="00:00:00.15" To="{x:Static SystemParameters.VerticalScrollBarWidth}"/>
<!--Line Down-->
<DoubleAnimation Storyboard.TargetName="PART_LineDownButton" Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="PART_LineDownButton" Storyboard.TargetProperty="Width" BeginTime="0" Duration="00:00:00.15" To="{x:Static SystemParameters.VerticalScrollBarWidth}"/>
</Storyboard>
</VisualState>
<VisualState Name="Pressed">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="PART_Track" Storyboard.TargetProperty="Width" BeginTime="0" Duration="0" To="{x:Static SystemParameters.VerticalScrollBarWidth}"/>
<DoubleAnimation Storyboard.TargetName="PART_TrackBackground" Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0" To="1"/>
<!--Line Up-->
<DoubleAnimation Storyboard.TargetName="PART_LineUpButton" Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="PART_LineUpButton" Storyboard.TargetProperty="Width" BeginTime="0" Duration="00:00:00.15" To="{x:Static SystemParameters.VerticalScrollBarWidth}"/>
<!--Line Down-->
<DoubleAnimation Storyboard.TargetName="PART_LineDownButton" Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0" To="1"/>
<DoubleAnimation Storyboard.TargetName="PART_LineDownButton" Storyboard.TargetProperty="Width" BeginTime="0" Duration="00:00:00.15" To="{x:Static SystemParameters.VerticalScrollBarWidth}"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition Height="*" MaxHeight="{x:Static SystemParameters.VerticalScrollBarButtonHeight}"/>
<RowDefinition Height="0.00001*"/>
<RowDefinition Height="*" MaxHeight="{x:Static SystemParameters.VerticalScrollBarButtonHeight}"/>
</Grid.RowDefinitions>
<RepeatButton
x:Name="PART_LineUpButton"
Command="{x:Static ScrollBar.LineUpCommand}"
Focusable="False"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Opacity="0"
Width="{StaticResource ScrollBarCollapsedWidth}"
Style="{StaticResource LineButton}"
>
<Path
x:Name="ArrowUp"
Data="{Binding Source={StaticResource ArrowUpGeometry}}"
Fill="{Binding Parent.Foreground, RelativeSource={RelativeSource Self}}"
/>
</RepeatButton>
<Track
x:Name="PART_Track"
Grid.Row="1"
IsDirectionReversed="True"
Focusable="False"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Width="{StaticResource ScrollBarCollapsedWidth}"
>
<Track.Thumb>
<Thumb x:Name="Thumb" Style="{StaticResource ScrollBarTrackThumb}">
<u:StateManager.Groups>
<u:StateGroupsManager AttachToMembers="True">
<u:StateDefinitionCollection>
<u:MouseStateDefinition MouseSource="{Binding Group.Target, RelativeSource={RelativeSource Self}}"/>
</u:StateDefinitionCollection>
</u:StateGroupsManager>
</u:StateManager.Groups>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="MouseStates">
<VisualState Name="Normal"/>
<VisualState Name="MouseOver">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" BeginTime="0" Duration="0" To="{StaticResource ThumbMouseOverColor}"/>
</Storyboard>
</VisualState>
<VisualState Name="Pressed">
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" BeginTime="0" Duration="0" To="{StaticResource ThumbPressedColor}"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Thumb.Background>
<SolidColorBrush Color="{StaticResource ThumbStaticColor}"/>
</Thumb.Background>
</Thumb>
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageDownCommand" Style="{StaticResource PageButton}"/>
</Track.IncreaseRepeatButton>
<Track.DecreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageUpCommand" Style="{StaticResource PageButton}"/>
</Track.DecreaseRepeatButton>
</Track>
<Rectangle
x:Name="PART_TrackBackground"
Grid.Row="1"
Panel.ZIndex="-1"
Focusable="False"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
IsHitTestVisible="False"
Opacity="0"
Width="{Binding ActualWidth, ElementName=PART_Track}"
>
<Shape.Fill>
<SolidColorBrush Color="{StaticResource TrackStaticBackgroundColor}"/>
</Shape.Fill>
</Rectangle>
<RepeatButton
x:Name="PART_LineDownButton"
Grid.Row="2"
Command="{x:Static ScrollBar.LineDownCommand}"
Focusable="False"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Opacity="0"
Width="{StaticResource ScrollBarCollapsedWidth}"
Style="{StaticResource LineButton}"
>
<Path
x:Name="ArrowDown"
Data="{Binding Source={StaticResource ArrowDownGeometry}}"
Fill="{Binding Parent.Foreground, RelativeSource={RelativeSource Self}}"
/>
</RepeatButton>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Thumb" Property="Visibility" Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="VerticalScrollBar" TargetType="c:AutoHideScrollBar">
<Setter Property="Template" Value="{StaticResource VerticalScrollBarTemplate}"/>
</Style>
<Style TargetType="ScrollViewer" BasedOn="{StaticResource {x:Type ScrollViewer}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ScrollViewer">
<Grid>
<ScrollContentPresenter
x:Name="PART_ScrollContentPresenter"
CanContentScroll="{TemplateBinding CanContentScroll}"
>
<ScrollContentPresenter.Clip>
<MultiBinding Converter="{x:Static c:AutoHideScrollBar.ScrollContentClipConverter}">
<Binding ElementName="PART_VerticalScrollBar" Path="VisibleWidth" Mode="OneWay"/>
<Binding ElementName="PART_HorizontalScrollBar" Path="VisibleHeight" Mode="OneWay"/>
<Binding RelativeSource="{RelativeSource Self}" Path="ActualWidth" Mode="OneWay"/>
<Binding RelativeSource="{RelativeSource Self}" Path="ActualHeight" Mode="OneWay"/>
</MultiBinding>
</ScrollContentPresenter.Clip>
</ScrollContentPresenter>
<c:AutoHideScrollBar
x:Name="PART_VerticalScrollBar"
Cursor="{TemplateBinding Cursor}"
HorizontalAlignment="Right"
HorizontalContentAlignment="Right"
Maximum="{TemplateBinding ScrollableHeight}"
Value="{TemplateBinding VerticalOffset}"
ViewportSize="{TemplateBinding ViewportHeight}"
Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
Template="{StaticResource VerticalScrollBarTemplate}"
>
</c:AutoHideScrollBar>
<c:AutoHideScrollBar
x:Name="PART_HorizontalScrollBar"
Cursor="{TemplateBinding Cursor}"
Maximum="{TemplateBinding ScrollableWidth}"
Orientation="Horizontal"
Value="{TemplateBinding HorizontalOffset}"
VerticalAlignment="Bottom"
VerticalContentAlignment="Bottom"
ViewportSize="{TemplateBinding ViewportWidth}"
Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
Template="{StaticResource HorizontalScrollBarTemplate}"
/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
@@ -0,0 +1,80 @@
using mbts.ui.converters;
using mbts.ui.extensions;
using System;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Media;
namespace mbts.ui.controls {
partial class AutoHideScrollbarResources : ResourceDictionary {
public AutoHideScrollbarResources() =>
InitializeComponent();
}
class AutoHideScrollBar : ScrollBar {
IDisposable _hooks;
public static IMultiValueConverter ScrollContentClipConverter =
ValueConverter.create<double, double, double, double, RectangleGeometry>(
(scroll_bar_width, scroll_bar_height, content_width, content_height) =>
new RectangleGeometry(
new Rect(new Size(
Math.Max(0, content_width - DoubleHelper.CoerceNaN(scroll_bar_width, 0)),
Math.Max(0, content_height - DoubleHelper.CoerceNaN(scroll_bar_height, 0))))));
#region VisibleWidth
static readonly DependencyPropertyKey VisibleWidthPropertyKey =
DependencyProperty.RegisterAttachedReadOnly(
nameof(VisibleWidth),
typeof(double),
typeof(AutoHideScrollBar),
new PropertyMetadata(double.NaN, null, CoerceVisibleWidth));
static object CoerceVisibleWidth(DependencyObject d, object baseValue) =>
(d as AutoHideScrollBar)?.Track?.ActualWidth ?? baseValue;
public static readonly DependencyProperty VisibleWidthProperty =
VisibleWidthPropertyKey.DependencyProperty;
public double VisibleWidth {
get => (double)GetValue(VisibleWidthProperty);
private set => SetValue(VisibleWidthPropertyKey, value);
}
#endregion
#region VisibleHeight
static readonly DependencyPropertyKey VisibleHeightPropertyKey =
DependencyProperty.RegisterAttachedReadOnly(
nameof(VisibleHeight),
typeof(double),
typeof(AutoHideScrollBar),
new PropertyMetadata(double.NaN, null, CoerceVisibleHeight));
static object CoerceVisibleHeight(DependencyObject d, object baseValue) =>
(d as AutoHideScrollBar)?.Track?.ActualHeight ?? baseValue;
public static readonly DependencyProperty VisibleHeightProperty =
VisibleHeightPropertyKey.DependencyProperty;
public double VisibleHeight {
get => (double)GetValue(VisibleHeightProperty);
private set => SetValue(VisibleHeightPropertyKey, value);
}
#endregion
public override void OnApplyTemplate() {
Disposable.dispose(ref _hooks);
/// call base method first to ensure <see cref="ScrollBar.Track"/> is initialized.
base.OnApplyTemplate();
_hooks = Track.SubscribeSizeChanged((s, e) => {
if (e.WidthChanged)
CoerceValue(VisibleWidthProperty);
if (e.HeightChanged)
CoerceValue(VisibleHeightProperty);
});
CoerceValue(VisibleWidthProperty);
CoerceValue(VisibleHeightProperty);
}
}
}
@@ -363,7 +363,8 @@ namespace mbts.ui.controls {
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
StrokeThickness = HighDpiExtensions.pixel_unit
}
},
IsClipEnabled = true
};
_drag_rect_adorner.Child.bind(Shape.FillProperty, _highlight_path, DIYGrid.SelectionHighlightBrushConverter, _grid);
_drag_rect_adorner.Child.bind(Shape.StrokeProperty, _highlight_path, DIYGrid.SelectionHighlightOpaqueBrushConverter, _grid);