private void SetPopupPosition()
{
if (colorBoard != null && Application.Current != null && Application.Current.Host != null && Application.Current.Host.Content != null)
{
double contentheight = Application.Current.Host.Content.ActualHeight;
double contentwidth = Application.Current.Host.Content.ActualWidth;
double colorboardheight = colorBoard.ActualHeight;
double colorboardwidth = colorBoard.ActualWidth;
double pickerheight = ActualHeight;
double pickerwidth = ActualWidth; if (rootElement != null)
{
GeneralTransform transform = rootElement.TransformToVisual(null);
if (transform != null)
{
Point point00 = transform.Transform( new Point(0.0, 0.0));
Point point10 = transform.Transform( new Point(1.0, 0.0));
Point point01 = transform.Transform( new Point(0.0, 1.0)); double x00 = point00.X;
double y00 = point00.Y;
double x = x00;
double y = y00 pickerheight; if (contentheight < (y colorboardheight))
{
y = y00 - colorboardheight;
}
if (contentwidth < (x colorboardwidth))
{
x = x00 pickerwidth - colorboardwidth;
} popupDropDown.HorizontalOffset = 0.0;
popupDropDown.VerticalOffset = 0.0;
canvasOutsidePopup.Width = contentwidth;
canvasOutsidePopup.Height = contentheight;
colorBoard.HorizontalAlignment = HorizontalAlignment.Left;
colorBoard.VerticalAlignment = VerticalAlignment.Top;
Canvas.SetLeft(colorBoard, x - x00);
Canvas.SetTop(colorBoard, y - y00); Matrix identity = Matrix.Identity;
identity.M11 = point10.X - point00.X;
identity.M12 = point10.Y - point00.Y;
identity.M21 = point01.X - point00.X;
identity.M22 = point01.Y - point00.Y;
identity.OffsetX = point00.X;
identity.OffsetY = point00.Y; MatrixTransform matrixtransform = new MatrixTransform();
InvertMatrix(ref identity); matrixtransform.Matrix = identity;
canvasOutsidePopup.RenderTransform = matrixtransform;
}
}
}
}
评论