changing attach ui from being in a ContextMenu to a Popup b/c of focus interaction issues w/ the new attach ui
This commit is contained in:
1 parent
d02e9cf0f9
commit
fb024ea3c2
1 file changed
+35
-21
@@ -778,17 +778,15 @@ namespace mbts.spark {
|
||||
//PresentationTraceSources.SetTraceLevel(_datacontext_binding, PresentationTraceLevel.High);
|
||||
|
||||
public override FrameworkElement view_factory() {
|
||||
var menu = new ContextMenu() {
|
||||
Name = "attach_button_context_menu"
|
||||
};
|
||||
|
||||
var popup = new System.Windows.Controls.Primitives.Popup();
|
||||
|
||||
#region Attach Button
|
||||
// create the attach button and assign the menu to it
|
||||
var attach_button = new Button() {
|
||||
Name = "attach_button",
|
||||
Content = "Attach",
|
||||
ContextMenu = menu,
|
||||
};
|
||||
attach_button.Click += (s, e) => { popup.IsOpen = !popup.IsOpen; };
|
||||
|
||||
var orderbook_vm_datacontext_binding = new Binding(_orderbook_vm_datacontext_binding_path);
|
||||
orderbook_vm_datacontext_binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, _mini_or_full_ob_type, 1);
|
||||
@@ -797,21 +795,16 @@ namespace mbts.spark {
|
||||
attach_button.SetBinding(Button.DataContextProperty, orderbook_vm_datacontext_binding);
|
||||
attach_button.SetBinding(Button.CommandProperty, new Binding(_begin_attach_command_binding_path));
|
||||
|
||||
// assign open & close behavior for the ContextMenu
|
||||
var behaviors = System.Windows.Interactivity.Interaction.GetBehaviors(attach_button);
|
||||
behaviors.Add(new DropDownButtonBehavior());
|
||||
#endregion
|
||||
|
||||
// assign the ContextMenu the DataContext of PlacementTarget, which will always be kept in sync with our parent button
|
||||
var cm_dc_binding = new Binding("PlacementTarget.DataContext");
|
||||
cm_dc_binding.RelativeSource = new RelativeSource(RelativeSourceMode.Self);
|
||||
menu.SetBinding(ContextMenu.DataContextProperty, cm_dc_binding);
|
||||
|
||||
#region OrderParamsPanel
|
||||
// finally, set the order_params DataContext to that of the ContextMenu
|
||||
var order_params = new mbts.ui.spark.OrderParamsPanel();
|
||||
var order_params = new mbts.ui.spark.OrderParamsPanel {
|
||||
Margin = new Thickness(6),
|
||||
ShowAlgoTypeNodes = true
|
||||
};
|
||||
var order_params_binding = new Binding(_orderbook_vm_attach_vm_binding_path);
|
||||
order_params_binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ContextMenu), 1);
|
||||
order_params_binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Popup), 1);
|
||||
order_params.SetBinding(OrderParamsPanel.DataContextProperty, order_params_binding);
|
||||
order_params.SetBinding(OrderParamsPanel.PriceProperty, new Binding(_price_binding_path));
|
||||
order_params.SetBinding(OrderParamsPanel.SizeProperty, new Binding(_size_binding_path));
|
||||
@@ -834,20 +827,41 @@ namespace mbts.spark {
|
||||
|
||||
// go find the OBVM on the ContextMenu to get the command
|
||||
var send_attach_button_binding = new Binding(_orderbook_vm_send_attached_orders_cmd_binding_path);
|
||||
send_attach_button_binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ContextMenu), 1);
|
||||
send_attach_button_binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Popup), 1);
|
||||
send_attached_orders_button.SetBinding(Button.CommandProperty, send_attach_button_binding);
|
||||
|
||||
// close the ContextMenu when the send attached button is clicked
|
||||
send_attached_orders_button.Click += (s,e) =>
|
||||
send_attached_orders_button.Click += (s, e) =>
|
||||
{
|
||||
menu.IsOpen = false;
|
||||
popup.IsOpen = false;
|
||||
};
|
||||
|
||||
var stack_p = new StackPanel() { Margin = new Thickness(0, 0, 0, 5) };
|
||||
stack_p.Children.Add(order_params);
|
||||
stack_p.Children.Add(send_attached_orders_button);
|
||||
#endregion
|
||||
|
||||
menu.Items.Add(order_params);
|
||||
menu.Items.Add(send_attached_orders_button);
|
||||
var border = new Border() {
|
||||
Background = BTSColors.common_background_brush,
|
||||
BorderThickness = new Thickness(1),
|
||||
Name = "attach_border",
|
||||
Child = stack_p,
|
||||
};
|
||||
|
||||
popup.Child = border;
|
||||
popup.StaysOpen = false;
|
||||
popup.PlacementTarget = attach_button;
|
||||
popup.Placement = PlacementMode.Bottom;
|
||||
// assign the Popup the DataContext of PlacementTarget, which will always be kept in sync with our parent button
|
||||
popup.SetBinding(Popup.DataContextProperty, new Binding("PlacementTarget.DataContext") {
|
||||
RelativeSource = new RelativeSource(RelativeSourceMode.Self)
|
||||
});
|
||||
|
||||
return attach_button;
|
||||
var the_whole_thing = new Grid();
|
||||
the_whole_thing.Children.Add(attach_button);
|
||||
the_whole_thing.Children.Add(popup);
|
||||
|
||||
return the_whole_thing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user