Remove ContextMenu from Badge and setup new Popup
This commit is contained in:
1 parent
9eb760b3c7
commit
ffaba90c96
2 files changed
+34
-31
No files matched your search
@@ -91,15 +91,26 @@ namespace mbts.spark {
|
||||
order.PropertyChanged += _order_PropertyChanged;
|
||||
// get the stackpanel it belongs in
|
||||
Panel panel = get_panel(price);
|
||||
//var coords = GetAbsolutePlacement(panel, true);
|
||||
// insert Badge and wire up DataContext
|
||||
if (panel != null) {
|
||||
panel.Children.Add(mkbadge(order));
|
||||
panel.Children.Add(mkbadge(order, panel));
|
||||
}
|
||||
} //else {
|
||||
//Log.Ui.warn($"Failed to add order ({order.id}): order already in {nameof(LadderGridHost)}'s {nameof(_orders)}.");
|
||||
//}
|
||||
}
|
||||
|
||||
public static Rect GetAbsolutePlacement(FrameworkElement element, bool relativeToScreen = false) {
|
||||
var absolutePos = element.PointToScreen(new System.Windows.Point(0, 0));
|
||||
if (relativeToScreen) {
|
||||
return new Rect(absolutePos.X, absolutePos.Y, element.ActualWidth, element.ActualHeight);
|
||||
}
|
||||
var posMW = Application.Current.MainWindow.PointToScreen(new System.Windows.Point(0, 0));
|
||||
absolutePos = new System.Windows.Point(absolutePos.X - posMW.X, absolutePos.Y - posMW.Y);
|
||||
return new Rect(absolutePos.X, absolutePos.Y, element.ActualWidth, element.ActualHeight);
|
||||
}
|
||||
|
||||
void _order_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
||||
if (e.PropertyName == nameof(LadderOrderVM.price)) {
|
||||
var order = (LadderOrderVM)sender;
|
||||
@@ -108,7 +119,7 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
Badge mkbadge(LadderOrderVM order) {
|
||||
Badge mkbadge(LadderOrderVM order, UIElement popup_placement_target) {
|
||||
Badge b = new Badge();
|
||||
b.DataContext = order;
|
||||
// Hook up the style from xaml
|
||||
@@ -118,31 +129,34 @@ namespace mbts.spark {
|
||||
if (e.ChangedButton == MouseButton.Middle) {
|
||||
// create the new popup window in here
|
||||
|
||||
b.ContextMenu.DataContext = order.orderbook_vm;
|
||||
var view = new MiniOrderBookView(order.orderbook_vm);
|
||||
var w = new Window();
|
||||
w.Content = view;
|
||||
w.Show();
|
||||
var popup = new System.Windows.Controls.Primitives.Popup();
|
||||
popup.Child = view;
|
||||
popup.StaysOpen = false;
|
||||
popup.PlacementTarget = popup_placement_target;
|
||||
popup.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
|
||||
popup.VerticalOffset = 5;
|
||||
popup.IsOpen = true;
|
||||
b.Popup = popup;
|
||||
|
||||
// close context menu after command executed
|
||||
if (curr_order != null) {
|
||||
Action command_executed = null;
|
||||
command_executed = () =>
|
||||
{
|
||||
try {
|
||||
b.ContextMenu.IsOpen = false;
|
||||
curr_order.command_executed -= command_executed;
|
||||
} catch (Exception ex) {
|
||||
Log.Ui.warn($"Error in {typeof(LadderGridHost)}'s {typeof(Badge)} {nameof(LadderOrderVM.command_executed)} local handler: {ex}");
|
||||
}
|
||||
};
|
||||
curr_order.command_executed += command_executed;
|
||||
}
|
||||
//if (curr_order != null) {
|
||||
// Action command_executed = null;
|
||||
// command_executed = () =>
|
||||
// {
|
||||
// try {
|
||||
// curr_order.command_executed -= command_executed;
|
||||
// } catch (Exception ex) {
|
||||
// Log.Ui.warn($"Error in {typeof(LadderGridHost)}'s {typeof(Badge)} {nameof(LadderOrderVM.command_executed)} local handler: {ex}");
|
||||
// }
|
||||
// };
|
||||
// curr_order.command_executed += command_executed;
|
||||
//}
|
||||
} else if (e.ChangedButton == MouseButton.Left) {
|
||||
if (curr_order?.cancel_command?.CanExecute(null) == true)
|
||||
curr_order.cancel_command.Execute(null);
|
||||
}
|
||||
};
|
||||
b.ContextMenuOpening += (s, e) => e.Handled = true;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
@@ -540,17 +540,6 @@
|
||||
<Setter Property="ParentAlgoType" Value="{Binding parent_algo_type}" />
|
||||
<Setter Property="ParentAlgoTypeBrush" Value="{Binding parent_algo_type_brush}" />
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Setter Property="ContextMenu">
|
||||
<Setter.Value>
|
||||
<ContextMenu>
|
||||
<ContextMenu.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="Hey you did it!" />
|
||||
</DataTemplate>
|
||||
</ContextMenu.ItemTemplate>
|
||||
</ContextMenu>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="{Binding hoverbackground}" />
|
||||
|
||||
Reference in new issue
Block a user