Contract Picker Model - OK and Cancel buttons behave as one would expect

This commit is contained in:
Jake Norbut committed 2017-12-05 18:43:35 -06:00
1 parent d2b9f6d620
commit 31392df28d
3 files changed
+28 -5

No files matched your search

@@ -35,7 +35,10 @@ namespace bts {
SizeToContent = SizeToContent.WidthAndHeight
};
picker.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (sender, e) => picker.Close()));
picker.Closing += (_,__) => _bus.post(next, vm.result);
vm.close_action = () => {
picker.Close();
_bus.post(next, vm.result);
};
picker.Show();
}
@@ -49,7 +52,10 @@ namespace bts {
SizeToContent = SizeToContent.WidthAndHeight
};
picker.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (sender, e) => picker.Close()));
picker.Closing += (_, __) => _bus.post(next, vm.result_criteria);
vm.close_action = () => {
picker.Close();
_bus.post(next, vm.result_criteria);
};
picker.Show();
}
@@ -49,13 +49,26 @@ namespace mbts.spark {
security_keys = selected_securities
});
criteria_input_name = string.Empty;
ok_button_command.TryRaiseCanExecuteChanged();
});
remove_criteria_command = new DelegateCommand(_ =>
{
security_criteria.Remove(selected_security_criteria_clause);
ok_button_command.TryRaiseCanExecuteChanged();
});
ok_button_command = new DelegateCommand(
execute: _ => { close_action?.Invoke(); },
can_execute: _ => {
if (!is_edit_mode) {
return (selected_securities.Count > 0);
} else {
return (security_criteria.Count > 0);
}
}
);
}
@@ -124,6 +137,7 @@ namespace mbts.spark {
internal void security_selection_changed(IEnumerable<SecurityImmutable> secs)
{
selected_securities = secs.Select(s => s.Id).ToList();
ok_button_command.TryRaiseCanExecuteChanged();
_compose_criteria_clause_name();
// _security_in_criteria is our fun to be returned to our callers
@@ -172,6 +186,7 @@ namespace mbts.spark {
public ICommand add_criteria_command { get; }
public ICommand remove_criteria_command { get; }
public ICommand ok_button_command { get; }
public ObservableCollection<SecurityCriteriaClause> security_criteria { get; } = new ObservableCollection<SecurityCriteriaClause>();
private SecurityCriteriaClause _selected_security_criteria_clause = new SecurityCriteriaClause();
@@ -193,6 +208,8 @@ namespace mbts.spark {
}
}
public Action close_action { get; set; }
public bool is_edit_mode { get; set; }
private SecurityCriteria _search_criteria;
@@ -18,7 +18,7 @@
<ColumnDefinition SharedSizeGroup="share_col_width" Width="Auto"/>
<ColumnDefinition SharedSizeGroup="share_col_width" Width="Auto"/>
<ColumnDefinition SharedSizeGroup="share_col_width" Width="Auto"/>
<ColumnDefinition Width="*" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<GroupBox Grid.Row="0" Grid.Column="0" Header="Exchanges">
<ListBox x:Name="_exchanges" Grid.Row ="1" Grid.Column="0" SelectionMode="{Binding is_edit_mode, Converter={StaticResource bool_to_selectmode}}" ItemsSource="{Binding all_exchanges}" Margin="2" ></ListBox>
@@ -34,8 +34,8 @@
</GroupBox>
</Grid>
<UniformGrid HorizontalAlignment="Right" Rows="1" Columns="2" DockPanel.Dock="Bottom" Margin="0,12,12,12">
<Button Width="50" Margin="12,0,0,0" Command="ApplicationCommands.Close">Ok</Button>
<Button Width="50" Margin="12,0,0,0">Cancel</Button>
<Button Width="50" Margin="12,0,0,0" Command="{Binding ok_button_command}">Ok</Button>
<Button Width="50" Margin="12,0,0,0" Command="ApplicationCommands.Close">Cancel</Button>
</UniformGrid>
<GroupBox Header="Picked instruments" DockPanel.Dock="Bottom" Margin="12,0,12,0" Visibility="{Binding is_edit_mode, Converter={StaticResource BoolToVisibility}}">
<Grid>