private void OnHostPopupOpened(object sender, object e)
{
// there seems to be some issue where the mesaure is happening too fast when the size
// of the flyout is 0,0. This attempts to solve this.
// credit to avidgator/jvlppm for suggestions on github project
if (_hostPopup.ActualHeight == 0 || _hostPopup.ActualWidth == 0)
{
SizeChangedEventHandler updatePosition = null;
updatePosition = (s, eP) =>
{
if (eP.NewSize.Width != 0 && eP.NewSize.Height != 0)
{
OnHostPopupOpened(s, eP);
SizeChanged -= updatePosition;
}
};
SizeChanged += updatePosition;
}
_hostPopup.HorizontalOffset = this.HorizontalOffset;
_hostPopup.VerticalOffset = this.VerticalOffset;
Measure(new Size(Double.PositiveInfinity, double.PositiveInfinity));
PerformPlacement(this.HorizontalOffset, this.VerticalOffset);
// handling the case where it isn't parented to the visual tree
// inspect the visual root and adjust.
if (_hostPopup.Parent == null)
{
Windows.UI.ViewManagement.InputPane.GetForCurrentView().Showing += OnInputPaneShowing;
Windows.UI.ViewManagement.InputPane.GetForCurrentView().Hiding += OnInputPaneHiding;
}
var content = Content as Control;
if (content != null)
content.Focus(Windows.UI.Xaml.FocusState.Programmatic);
}