Skip to content

Commit

Permalink
Fixing referenced element for popup placement (#3344)
Browse files Browse the repository at this point in the history
Possibly a fix for #3316
  • Loading branch information
Keboo authored Oct 22, 2023
1 parent b8331d1 commit 2d2a38a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions MaterialDesignThemes.Wpf/ComboBoxPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private CustomPopupPlacement[] ComboBoxCustomPopupPlacementCallback(

var visualAncestry = PlacementTarget.GetVisualAncestry().ToList();

var parent = visualAncestry.OfType<Panel>().ElementAt(1);
var parent = visualAncestry.OfType<Panel>().First();
VisiblePlacementWidth = TreeHelper.GetVisibleWidth((FrameworkElement)PlacementTarget, parent, FlowDirection);

var data = GetPositioningData(visualAncestry, popupSize, targetSize);
Expand All @@ -246,12 +246,10 @@ PositioningData GetPositioningData(IEnumerable<DependencyObject?> visualAncestry
{
var locationFromScreen = PlacementTarget.PointToScreen(new Point(0, 0));

var mainVisual = visualAncestry.OfType<Visual>().LastOrDefault();
if (mainVisual is null) throw new ArgumentException($"{nameof(visualAncestry)} must contains at least one {nameof(Visual)} control inside.");

var controlVisual = visualAncestry.OfType<Visual>().FirstOrDefault();
if (controlVisual == null) throw new ArgumentException($"{nameof(visualAncestry)} must contains at least one {nameof(Visual)} control inside.");

var mainVisual = visualAncestry.OfType<Visual>().LastOrDefault()
?? throw new ArgumentException($"{nameof(visualAncestry)} must contains at least one {nameof(Visual)} control inside.");
var controlVisual = visualAncestry.OfType<Visual>().FirstOrDefault()
?? throw new ArgumentException($"{nameof(visualAncestry)} must contains at least one {nameof(Visual)} control inside.");
var screen = Screen.FromPoint(locationFromScreen);
var screenWidth = (int)screen.Bounds.Width;
var screenHeight = (int)screen.Bounds.Height;
Expand Down

0 comments on commit 2d2a38a

Please sign in to comment.