Recently we moved our WPF Application on dot net 6, and we discovered that one of the one of the control is not working. It kind of a custom combo box control that work as a popup to a button, so whenever we click on the button a popup is shown, but after migration that pop up is not visible.
// this is the control that is supposed to popup on button click
public class BalloonControl : ContentControl
{
static BalloonControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(BalloonControl), new FrameworkPropertyMetadata(typeof(BalloonControl)));
}
// some properties like
public void Show()
{
_Popup = new Popup()
{
RenderTransform = new ScaleTransform(App.Window.ApplicationScale, App.Window.ApplicationScale),
Focusable = true,
MinWidth = MinWidth,
PlacementTarget = Target as FrameworkElement,
Child = this,
AllowsTransparency = true,
StaysOpen = false,
Placement = Placement,
PlacementRectangle = PlacementRectangle,
PopupAnimation = PopupAnimation.Slide
};
this.SizeChanged += (s, e) =>
{
if (Placement == PlacementMode.Top || Placement == PlacementMode.Bottom)
{
if (UseCanvasScale)
{
Graphic.GraphicCanvas canvas = Graphic.GraphicCanvas.FocusedCanvas;
_Popup.HorizontalOffset = (-e.NewSize.Width / 2) / canvas.CanvasScale.ScaleX;
}
else
{
_Popup.HorizontalOffset = -e.NewSize.Width / 2;
}
}
};
_Popup.Opened += (s, e) =>
{
Mouse.Capture(_Popup.Child, CaptureMode.SubTree);
// right now up or down only
if (PointerOrientation == Common.PointerOrientation.Bottom)
{
var target = Target as FrameworkElement;
if (target != null)
{
Point pt = target.TranslatePoint(PlacementRectangle.TopLeft, Content as FrameworkElement);
if (pt.Y > 0)
{
PointerOrientation = QSC.Common.PointerOrientation.Top;
}
}
}
};
_Popup.Closed += (s, e) =>
{
if( IsCancelled )
{
if (OnCancel != null) OnCancel(this, new EventArgs());
}
else
{
if (OnApply != null) OnApply(this, new EventArgs());
}
};
_Popup.IsOpen = true;
}
}
// This is how the above piece of code is being called
onButtonclick()
{
Graphic.GraphicCanvas.FocusedCanvas = canvas;
// show popup
var list = new windows.ComboBoxPopup()
{
MinWidth = Style.Size.Width * canvas.CanvasScale.ScaleX,
MaxHeight = 1080 * canvas.CanvasScale.ScaleY,
FontSize = CssStyle.FontSize * canvas.CanvasScale.ScaleX,
};
list.Background = Brushes.Transparent;
Util.FontManager.StuffControl(CssStyle, list);
//Point tx = TransformToVisual(canvas).Transform(new Point(rc.Width / 2, 0));
Point tx = new Point((rc.Width / 2) + rc.X, rc.Y);
list.Choices = Style.Value.Choices.Select(c => new ListBoxItem(c, ActualTextColor, CssStyle) { HorizontalAlignment = Design.AlignmentConverters.ToWindows(_Overrider.HorizontalAlignment) } );
list.SelectedValue = list.Choices.FirstOrDefault(v => v.JSON == Style.Value.String);
double scale = canvas.CanvasScale.ScaleX;
var balloon = new windows.BalloonControl()
{
MinWidth = Style.Size.Width * scale,
Content = list,
Ratio = 0.5,
Foreground = new SolidColorBrush(_Style.TextColor),
Target = GraphicCanvas,
Placement = PlacementMode.Bottom,
PlacementRectangle = new Rect(tx.X, tx.Y, Size.Width, Size.Height),
Background = Util.Frozen.CreateBrush(CssStyle.BackgroundColor),
BorderBrush = Util.Frozen.CreateBrush(CssStyle.Border2.Color.Left)
};
ballon.show();
}
When I remove the Content, which a content propert in ContentControl class, from the balloon object and set listbox as child directly in BallononControl show method, the pop up works, just styling is the issue.
I’m mostly concerned with why this behavior is happening is there something I can do to fix it.