private void OnResizeBothDelta(object sender, DragDeltaEventArgs e)
{
// Set height
SetDragHeight(e);
// Set width
menuPanel.Width = Double.NaN;
if (Double.IsNaN(galleryPanel.Width)) galleryPanel.Width = galleryPanel.ActualWidth;
double monitorRight = RibbonControl.GetControlMonitor(this).Right;
FrameworkElement popupChild = popup.Child as FrameworkElement;
double delta = monitorRight - this.PointToScreen(new Point()).X - popupChild.ActualWidth - e.HorizontalChange;
double deltaX = popupChild.ActualWidth - galleryPanel.ActualWidth;
double deltaBorders = dropDownBorder.ActualWidth - galleryPanel.ActualWidth;
if (delta > 0) galleryPanel.Width = Math.Max(galleryPanel.Width + e.HorizontalChange, ActualWidth - deltaBorders);
else
{
galleryPanel.Width = Math.Max(monitorRight - this.PointToScreen(new Point()).X - deltaX, ActualWidth - deltaBorders);
}
}