diff --git a/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml b/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml index 5015098bd..613cbb580 100644 --- a/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml +++ b/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml @@ -29,6 +29,10 @@ #FF000000 + + + + @@ -439,7 +443,7 @@ @@ -492,7 +496,7 @@ @@ -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 @@ - + @@ -1080,7 +1083,7 @@ - + diff --git a/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml.cs b/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml.cs index 984aad62a..f0f0a6beb 100644 --- a/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml.cs +++ b/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml.cs @@ -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(level => level + 1), GroupLevelMarginConverter = ValueConverter.create(level => new Thickness(24 * level, 0, 0, 0)), + HeaderRowHeightConverter = new RangeBlockConverter { Minimum = MinHeaderRowHeight }, ExpandedVisualStateConverter = ValueConverter.create(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(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((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 diff --git a/src/client/spark/view/Converters/RangeBlockConverter.cs b/src/client/spark/view/Converters/RangeBlockConverter.cs new file mode 100644 index 000000000..b017e8dd0 --- /dev/null +++ b/src/client/spark/view/Converters/RangeBlockConverter.cs @@ -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 : IValueConverter where T : struct, IComparable { + 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(); + } +} diff --git a/src/client/spark/view/Utility/BindingHelper.cs b/src/client/spark/view/Utility/BindingHelper.cs new file mode 100644 index 000000000..00dffa4e2 --- /dev/null +++ b/src/client/spark/view/Utility/BindingHelper.cs @@ -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; + } + } +}