making row stay in edit mode when a change has not yet been committed but the selection has been moved off the row
This commit is contained in:
1 parent
dba3b9371c
commit
62d06180ea
5 files changed
+51
-12
No files matched your search
@@ -62,7 +62,7 @@
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<AdornerDecorator>
|
||||
<Border BorderThickness="2">
|
||||
<Border BorderThickness="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
|
||||
@@ -718,7 +718,7 @@ namespace mbts.spark {
|
||||
|
||||
public override FrameworkElement view_factory() {
|
||||
var tick_up_down = new TickUpDownNullableUIntCommit();
|
||||
tick_up_down.SetBinding(TickUpDownNullableUIntCommit.SourceValueProperty, nameof(OrderBookRowVM.quantity));
|
||||
tick_up_down.SetBinding(TickUpDownNullableUIntCommit.SourceValueProperty, nameof(OrderBookRowVM.prospective_quantity));
|
||||
tick_up_down.SetBinding(TickUpDownNullableUIntCommit.OnCommitProperty, nameof(OrderBookRowVM.modify_order_quantity));
|
||||
return tick_up_down;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,17 @@ namespace mbts.spark {
|
||||
bool _is_parent, _is_expanded, _is_selected;
|
||||
int _depth_level;
|
||||
SecurityMD? _security_md => order_tuple.security_md;
|
||||
|
||||
Property<uint> _prospective_quantity;
|
||||
Property<bool> _is_qty_dirty;
|
||||
|
||||
|
||||
public OrderBookRowVM(OrderBookVM owner, OrderRecordTuple order_tuple, bool is_expanded) {
|
||||
_owner = owner;
|
||||
this.order_tuple = order_tuple;
|
||||
is_visible = !is_child;
|
||||
_is_expanded = is_expanded;
|
||||
_prospective_quantity = backing(nameof(prospective_quantity), this.quantity);
|
||||
_is_qty_dirty = backing(nameof(is_qty_dirty), () => this.prospective_quantity != this.quantity, nameof(prospective_quantity), nameof(quantity));
|
||||
this.invalidated += OrderBookRowVM_invalidated;
|
||||
}
|
||||
|
||||
@@ -90,6 +95,17 @@ namespace mbts.spark {
|
||||
get => _is_selected;
|
||||
set => Set(ref _is_selected, value);
|
||||
}
|
||||
public uint prospective_quantity {
|
||||
get => _prospective_quantity.Value;
|
||||
set => _prospective_quantity.set(value);
|
||||
}
|
||||
|
||||
public bool is_qty_dirty {
|
||||
get => _is_qty_dirty.Value;
|
||||
set => _is_qty_dirty.set(value);
|
||||
}
|
||||
|
||||
|
||||
// Commands
|
||||
public ICommand toggle_command => _toggle_expanded_cmd ?? (
|
||||
_toggle_expanded_cmd = new DelegateCommand(() => is_expanded = !is_expanded));
|
||||
@@ -103,9 +119,9 @@ namespace mbts.spark {
|
||||
public ICommand modify_order_quantity => _modify_order_quantity ??
|
||||
(_modify_order_quantity = new DelegateCommand(
|
||||
(desired_quantity) => _owner.modify_order_quantity(this, (uint)desired_quantity),
|
||||
(desired_quantity) => desired_quantity != null &&
|
||||
this.status == OrderStatus.Working &&
|
||||
(uint)desired_quantity != this.quantity
|
||||
(desired_quantity) =>
|
||||
(desired_quantity != null && this.status == OrderStatus.Working && (uint)desired_quantity != this.quantity)
|
||||
|| prospective_quantity != this.quantity
|
||||
)
|
||||
);
|
||||
|
||||
@@ -133,6 +149,8 @@ namespace mbts.spark {
|
||||
// however, the order-type and security cells DO use databindings - if these cells have changed, the PropertyChanged event must be raised regardless of whether or not invalidated is raised
|
||||
if (old_order.order_type() != order.order_type())
|
||||
RaisePropertyChanged(nameof(order_type), nameof(order_metadata));
|
||||
if (old_order.quantity() != order.quantity())
|
||||
RaisePropertyChanged(nameof(quantity));
|
||||
if (!had_security && _security_md.HasValue) {
|
||||
RaisePropertyChanged(nameof(security), nameof(security_text));
|
||||
// need to raise invalidated to refresh the price cells (the security.ContractSpec determines how they are formatted - Ticks!)
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:mbts.ui.controls"
|
||||
mc:Ignorable="d"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
d:DesignHeight="100" d:DesignWidth="800" x:Name="_me">
|
||||
@@ -38,6 +37,7 @@
|
||||
</Button>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
<c:JakeTemplateConverter x:Key="test" NormalTemplate="{StaticResource ReadTemplate}" EditableTemplate="{StaticResource EditTemplate}"/>
|
||||
</UserControl.Resources>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ContentControl x:Name="read_only_or_edit">
|
||||
@@ -48,6 +48,9 @@
|
||||
<DataTrigger Binding="{Binding is_selected}" Value="True">
|
||||
<Setter Property="Template" Value="{StaticResource EditTemplate}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding is_qty_dirty}" Value="True">
|
||||
<Setter Property="Template" Value="{StaticResource EditTemplate}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ContentControl.Style>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -24,7 +25,8 @@ namespace mbts.ui.controls {
|
||||
DependencyProperty.Register("SourceValue",
|
||||
typeof(uint?),
|
||||
typeof(TickUpDownNullableUIntCommit),
|
||||
new PropertyMetadata {
|
||||
new FrameworkPropertyMetadata {
|
||||
BindsTwoWayByDefault = true,
|
||||
PropertyChangedCallback = source_value_changed
|
||||
}
|
||||
);
|
||||
@@ -51,10 +53,6 @@ namespace mbts.ui.controls {
|
||||
|
||||
public TickUpDownNullableUIntCommit() {
|
||||
InitializeComponent();
|
||||
|
||||
var content_control = read_only_or_edit.Template.LoadContent() as FrameworkElement;
|
||||
var qty = content_control.FindName("qty_ticker") as TickUpDownNullableUInt;
|
||||
|
||||
}
|
||||
|
||||
//private void Commit_button_Click(object sender, RoutedEventArgs e) {
|
||||
@@ -66,4 +64,24 @@ namespace mbts.ui.controls {
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
class JakeTemplateConverter : IValueConverter {
|
||||
public ControlTemplate NormalTemplate { get; set; }
|
||||
public ControlTemplate EditableTemplate { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is mbts.spark.OrderBookRowVM vm) {
|
||||
if (vm.is_qty_dirty || vm.is_selected) {
|
||||
return EditableTemplate;
|
||||
}
|
||||
return NormalTemplate;
|
||||
}
|
||||
return NormalTemplate;
|
||||
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user