本文整理汇总了C#中System.Windows.Controls.Control.TransformToVisual方法的典型用法代码示例。如果您正苦于以下问题:C# Control.TransformToVisual方法的具体用法?C# Control.TransformToVisual怎么用?C# Control.TransformToVisual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Control
的用法示例。
在下文中一共展示了Control.TransformToVisual方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArrangePopup
public void ArrangePopup(Popup ElementPopup,
Canvas ElementPopupChildCanvas,
Canvas ElementOutsidePopup,
FrameworkElement ElementPopupChild,
ContentControl LeaderPopupContent,
StackPanel ElementPopupChildMaxRangeStackPanel,
Control AssociatedControl,
ExpandDirection ExpandDirection,
bool EnforceMinWidth = true,
bool isNestedPopup = true
)
{
if (ElementPopup != null && AssociatedControl != null)
{
bool isRTL = (AssociatedControl.FlowDirection == FlowDirection.RightToLeft);
System.Windows.Interop.Content content = System.Windows.Application.Current.Host.Content;
double applicationWidth = content.ActualWidth;
double applicationHeight = content.ActualHeight;
double popupWidth = ElementPopupChild.ActualWidth;
double popupHeight = ElementPopupChild.ActualHeight;
if ((applicationHeight != 0.0) && (applicationWidth != 0.0))
{
GeneralTransform transform = AssociatedControl.TransformToVisual(null);
if (isRTL && transform is MatrixTransform)
{
var mt = (MatrixTransform) transform;
transform = new MatrixTransform
{
Matrix = new Matrix
{
M11 = mt.Matrix.M11,
M12 = mt.Matrix.M12,
M21 = mt.Matrix.M21,
M22 = mt.Matrix.M22,
OffsetX = mt.Matrix.OffsetX - AssociatedControl.ActualWidth,
OffsetY = mt.Matrix.OffsetY,
}
};
}
if (transform != null)
{
Point topLeftTransPoint = new Point(0.0, 0.0);
Point topRightTransPoint = new Point(1.0, 0.0);
Point bottomLeftTransPoint = new Point(0.0, 1.0);
Point topLeftPosition = transform.Transform(topLeftTransPoint);
Point topRightPosition = transform.Transform(topRightTransPoint);
Point bottomLeftPosition = transform.Transform(bottomLeftTransPoint);
double xDropDown = topLeftPosition.X;
double yDropDown = topLeftPosition.Y;
double widthRatio = Math.Abs((double)(topRightPosition.X - topLeftPosition.X));
double heightRatio = Math.Abs((double)(bottomLeftPosition.Y - topLeftPosition.Y));
double heightDropDown = AssociatedControl.ActualHeight * heightRatio;
double widthDropDown = AssociatedControl.ActualWidth * widthRatio;
double yBottomDropDown = yDropDown + heightDropDown;
if ((heightDropDown != 0.0) && (widthDropDown != 0.0))
{
popupWidth *= widthRatio;
popupHeight *= heightRatio;
double maxDropDownHeight = double.PositiveInfinity;
if (ExpandDirection == ExpandDirection.BottomLeft)
{
if (double.IsInfinity(maxDropDownHeight) || double.IsNaN(maxDropDownHeight))
maxDropDownHeight = ((applicationHeight - heightDropDown) * 3.0) / 5.0;
bool flag = true;
if (applicationHeight < (yBottomDropDown + popupHeight))
{
flag = false;
yBottomDropDown = yDropDown - popupHeight;
if (yBottomDropDown < 0.0)
{
if (yDropDown < ((applicationHeight - heightDropDown) / 2.0))
{
flag = true;
yBottomDropDown = yDropDown + heightDropDown;
}
else
{
flag = false;
yBottomDropDown = yDropDown - popupHeight;
}
}
}
if (popupHeight != 0.0)
{
if (flag)
maxDropDownHeight = Math.Min(applicationHeight - yBottomDropDown, maxDropDownHeight);
else
maxDropDownHeight = Math.Min(yDropDown, maxDropDownHeight);
}
}
else
{
if (double.IsInfinity(maxDropDownHeight) || double.IsNaN(maxDropDownHeight))
maxDropDownHeight = applicationHeight - 2 * RIGHT_CENTER_TOP_BOTTOM_MARGIN;
}
popupWidth = Math.Min(popupWidth, applicationWidth);
popupHeight = Math.Min(popupHeight, maxDropDownHeight);
popupWidth = Math.Max(widthDropDown, popupWidth);
double applicationRemainWidth = 0.0;
double leaderWidth = GetFrameworkElementWidth(LeaderPopupContent);
//.........这里部分代码省略.........
示例2: GemButtonClick
public void GemButtonClick(Item gem, Control relativeTo, Action<Item> callback)
{
gemCallback = null;
ComparisonGemList.SelectedItem = gem;
GeneralTransform gt = relativeTo.TransformToVisual(LayoutRoot);
Point offset = gt.Transform(new Point(relativeTo.ActualWidth + 4, 0));
GemPopup.VerticalOffset = offset.Y;
GemPopup.HorizontalOffset = offset.X;
ComparisonGemList.Measure(App.Current.RootVisual.RenderSize);
// this doesn't work in WPF
// The specified Visual and this Visual do not share a common ancestor, so there is no valid transformation between the two Visuals.
#if SILVERLIGHT
GeneralTransform transform = relativeTo.TransformToVisual(App.Current.RootVisual);
double distBetweenBottomOfPopupAndBottomOfWindow =
App.Current.RootVisual.DesiredSize.Height -
transform.Transform(new Point(0, ComparisonGemList.DesiredSize.Height)).Y;
if (distBetweenBottomOfPopupAndBottomOfWindow < 0)
{
GemPopup.VerticalOffset += distBetweenBottomOfPopupAndBottomOfWindow;
}
#else
// use PlacementTarget for WPF
GemPopup.PlacementTarget = LayoutRoot;
#endif
ComparisonGemList.IsShown = true;
GemPopup.IsOpen = true;
ComparisonGemList.Focus();
gemCallback = callback;
}
示例3: MetaButtonClick
public void MetaButtonClick(Item meta, Control relativeTo, Action<Item> callback)
{
metaCallback = null;
ComparisonMetaList.SelectedItem = meta;
GeneralTransform gt = relativeTo.TransformToVisual(LayoutRoot);
Point offset = gt.Transform(new Point(relativeTo.ActualWidth + 4, 0));
MetaPopup.VerticalOffset = offset.Y;
MetaPopup.HorizontalOffset = offset.X;
ComparisonMetaList.Measure(App.Current.RootVisual.RenderSize);
#if SILVERLIGHT
GeneralTransform transform = relativeTo.TransformToVisual(App.Current.RootVisual);
double distBetweenBottomOfPopupAndBottomOfWindow =
App.Current.RootVisual.DesiredSize.Height -
transform.Transform(new Point(0, ComparisonMetaList.DesiredSize.Height)).Y;
if (distBetweenBottomOfPopupAndBottomOfWindow < 0)
{
MetaPopup.VerticalOffset += distBetweenBottomOfPopupAndBottomOfWindow;
}
#else
// use PlacementTarget for WPF
GemPopup.PlacementTarget = LayoutRoot;
#endif
ComparisonMetaList.IsShown = true;
MetaPopup.IsOpen = true;
ComparisonMetaList.Focus();
metaCallback = callback;
}
示例4: GetPopupLocation
private static Point GetPopupLocation(Control parent)
{
var transform = parent.TransformToVisual(Application.Current.RootVisual);
var location = transform.Transform(new Point(parent.ActualWidth, 0));
return new Point(location.X + 8, location.Y - 28);
}