PNLView - get rid of magic const row height
This commit is contained in:
1 parent
5e6b048013
commit
ccb192887a
4 files changed
+89
-19
No files matched your search
@@ -29,6 +29,10 @@
|
||||
<Color x:Key="GroupRowForegroundColor">#FF000000</Color>
|
||||
<!--Converters-->
|
||||
<cv:GridLengthConverter x:Key="GridLengthPixelConverter" UnitType="Pixel"/>
|
||||
<cv:ValueConverterPipe x:Key="GroupRowHeightConverter">
|
||||
<cv:RangeBlockConverter Minimum="{x:Static pnl:PNLView.MinGroupRowHeight}"/>
|
||||
<cv:GridLengthConverter UnitType="Pixel"/>
|
||||
</cv:ValueConverterPipe>
|
||||
<cv:MultiValueConverterPipe x:Key="GroupRowBackgroundConverter">
|
||||
<cv:PartialConverter/>
|
||||
<cv:ColorToBrushConverter/>
|
||||
@@ -439,7 +443,7 @@
|
||||
<Grid
|
||||
c:DIYGrid.SyncWithColumnGeometrySource="{Binding ElementName=_grid}"
|
||||
c:DIYGrid.SyncWithColumnGeometry="True"
|
||||
Height="{Binding RowHeight, ElementName=_grid}"
|
||||
Height="{Binding RowHeight, ElementName=_grid, Converter={x:Static pnl:PNLView.HeaderRowHeightConverter}}"
|
||||
>
|
||||
<Grid.Visibility>
|
||||
<Binding Path="header_row_display">
|
||||
@@ -492,7 +496,7 @@
|
||||
<Grid
|
||||
c:DIYGrid.SyncWithColumnGeometrySource="{Binding ElementName=_grid}"
|
||||
c:DIYGrid.SyncWithColumnGeometry="True"
|
||||
Height="{Binding RowHeight, ElementName=_grid}"
|
||||
Height="{Binding RowHeight, ElementName=_grid, Converter={x:Static pnl:PNLView.HeaderRowHeightConverter}}"
|
||||
>
|
||||
<Grid.Visibility>
|
||||
<Binding Path="header_row_display">
|
||||
@@ -542,7 +546,6 @@
|
||||
c:DIYGrid.CachedColumnParamsContainer="{Binding RelativeSource={RelativeSource AncestorType=pnl:PNLView}}"
|
||||
VirtualizingPanel.ScrollUnit="Pixel"
|
||||
ScrollViewer.CanContentScroll="True"
|
||||
RowHeight="24"
|
||||
Rows="{Binding rows_view}"
|
||||
SelectionHighlight="{Binding selection_highlight}"
|
||||
SupportGroupItems="True"
|
||||
@@ -986,7 +989,7 @@
|
||||
<!--Row Template-->
|
||||
<c:DIYGrid.RowTemplate>
|
||||
<DataTemplate>
|
||||
<Grid c:DIYGrid.SyncWithColumnGeometry="True" usp:GridAnimation.RowAnimation="{Binding animations}">
|
||||
<Grid c:DIYGrid.SyncWithColumnGeometry="True" usp:GridAnimation.RowAnimation="{Binding animations}" Height="{Binding RowHeight, RelativeSource={RelativeSource AncestorType=c:DIYGrid}}">
|
||||
<Grid.Background>
|
||||
<SolidColorBrush Color="{Binding DataContext.grid_background_color, RelativeSource={RelativeSource AncestorType=pnl:PNLView}}"/>
|
||||
</Grid.Background>
|
||||
@@ -1080,7 +1083,7 @@
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="{Binding RowHeight, RelativeSource={RelativeSource AncestorType=c:DIYGrid}, Converter={StaticResource GridLengthPixelConverter}}"/>
|
||||
<RowDefinition Height="{Binding RowHeight, RelativeSource={RelativeSource AncestorType=c:DIYGrid}, Converter={StaticResource GroupRowHeightConverter}}"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Rectangle Grid.ColumnSpan="99" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stroke="Gray" StrokeThickness="1"/>
|
||||
|
||||
@@ -4,8 +4,8 @@ using mbts.collections;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.controls.adorners;
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.dpi;
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
@@ -14,9 +14,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
@@ -31,6 +29,9 @@ namespace bts.shell.pnl {
|
||||
}
|
||||
|
||||
partial class PNLView : UserControl {
|
||||
public static readonly double
|
||||
MinGroupRowHeight = 24.0.RoundLayoutValue(),
|
||||
MinHeaderRowHeight = 24.0.RoundLayoutValue();
|
||||
DIYGridPopupManager _popup_man_backing;
|
||||
|
||||
public enum Columns {
|
||||
@@ -87,6 +88,7 @@ namespace bts.shell.pnl {
|
||||
public static readonly IValueConverter
|
||||
IncrementalGroupLevelConverter = ValueConverter.create<int, int>(level => level + 1),
|
||||
GroupLevelMarginConverter = ValueConverter.create<int, Thickness>(level => new Thickness(24 * level, 0, 0, 0)),
|
||||
HeaderRowHeightConverter = new RangeBlockConverter<double> { Minimum = MinHeaderRowHeight },
|
||||
ExpandedVisualStateConverter = ValueConverter.create<bool, string>(is_expanded => is_expanded ? "Expanded" : "Collapsed");
|
||||
|
||||
public static readonly IMultiValueConverter
|
||||
@@ -165,17 +167,22 @@ namespace bts.shell.pnl {
|
||||
void _grid_loaded(object sender, RoutedEventArgs e) {
|
||||
// this is a hack to make room for the 'totals row' between the column headers and the regular rows.
|
||||
if (_grid.try_find_descendent_of_type(out DIYGridRowsPresenter rp)) {
|
||||
rp.SetBinding(MarginProperty, new Binding(nameof(PNLVM.header_row_display)) {
|
||||
Converter = ValueConverter.create<PNLHeaderRowDisplay, Thickness>(hrd => {
|
||||
double top = 0;
|
||||
if ((hrd & PNLHeaderRowDisplay.Total) != 0)
|
||||
top += 24;
|
||||
if ((hrd & PNLHeaderRowDisplay.SelectedTotal) != 0)
|
||||
top += 24;
|
||||
return new Thickness(0, top, 0, 0);
|
||||
}),
|
||||
Source = DataContext
|
||||
});
|
||||
rp.SetBinding(MarginProperty,
|
||||
BindingHelper.create_multi(
|
||||
ValueConverter.create<PNLHeaderRowDisplay, double, Thickness>((hrd, row_height) => {
|
||||
double top = 0;
|
||||
if ((hrd & PNLHeaderRowDisplay.Total) != 0)
|
||||
top += row_height;
|
||||
if ((hrd & PNLHeaderRowDisplay.SelectedTotal) != 0)
|
||||
top += row_height;
|
||||
return new Thickness(0, top, 0, 0);
|
||||
}),
|
||||
new Binding(nameof(PNLVM.header_row_display)),
|
||||
new Binding {
|
||||
Path = new PropertyPath(DIYGrid.RowHeightProperty),
|
||||
Converter = HeaderRowHeightConverter,
|
||||
Source = _grid
|
||||
}));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.converters {
|
||||
class RangeBlockConverter : IValueConverter {
|
||||
public IComparable Minimum { get; set; }
|
||||
public IComparable Maximum { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is IComparable comp) {
|
||||
if (Minimum != null && comp.CompareTo(Minimum) < 0)
|
||||
return Minimum;
|
||||
if (Maximum != null && comp.CompareTo(Maximum) > 0)
|
||||
return Maximum;
|
||||
} else {
|
||||
return new ValidationResult(false, $"Value does not implement {typeof(IComparable)}.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
class RangeBlockConverter<T> : IValueConverter where T : struct, IComparable<T> {
|
||||
public T? Maximum { get; set; }
|
||||
public T? Minimum { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is T v) {
|
||||
if (Minimum.HasValue && v.CompareTo(Minimum.Value) < 0)
|
||||
return Minimum.Value;
|
||||
if (Maximum.HasValue && v.CompareTo(Maximum.Value) > 0)
|
||||
return Maximum.Value;
|
||||
} else {
|
||||
return new ValidationResult(false, $"Value is not of type {typeof(T)}.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui {
|
||||
static class BindingHelper {
|
||||
public static MultiBinding create_multi(IMultiValueConverter converter, params Binding[] bindings) {
|
||||
var mb = new MultiBinding {
|
||||
Converter = converter
|
||||
};
|
||||
for (int i = 0; i < bindings.Length; i++)
|
||||
mb.Bindings.Add(bindings[i]);
|
||||
return mb;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user