Popup not working dotnet 6
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/Popup-not-working-dotnet-6/10698542)._
---
[severity:I'm unable to use this version]
I have a class that Inherit ContentControl and contains a method Show() that initializes a popup and shows it. We recently migrated our application to dotnet 6 and everything seems to work fine but this popup does not shows correctly.
Here a snippet of code:
```
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 = 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 this code is being utilize:
```
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();
}
```
This work fine in previous version but after upgrading it to dotnet 6 it doesn't work.
Also it was notice that if I change the content in popup and set it as comboBoxpopUp it work again.
So basically I'm just confused with this behavior and have no idea why it is working in previous version but not in dotnet 6.
---
### Original Comments
#### Feedback Bot on 7/9/2024, 07:56 AM:
(private comment, text removed)
---
### Original Solutions
(no solutions)
Contributor guide
Assessment
This issue has not been assessed yet.