本文整理汇总了C#中IVisual.TransformToVisual方法的典型用法代码示例。如果您正苦于以下问题:C# IVisual.TransformToVisual方法的具体用法?C# IVisual.TransformToVisual怎么用?C# IVisual.TransformToVisual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVisual
的用法示例。
在下文中一共展示了IVisual.TransformToVisual方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BringDescendentIntoView
/// <summary>
/// Attempts to bring a portion of the target visual into view by scrolling the content.
/// </summary>
/// <param name="target">The target visual.</param>
/// <param name="targetRect">The portion of the target visual to bring into view.</param>
/// <returns>True if the scroll offset was changed; otherwise false.</returns>
public bool BringDescendentIntoView(IVisual target, Rect targetRect)
{
if (Child != null)
{
var transform = target.TransformToVisual(Child);
var rect = targetRect * transform;
var offset = Offset;
var result = false;
if (rect.Bottom > offset.Y + Viewport.Height)
{
offset = offset.WithY((rect.Bottom - Viewport.Height) + Child.Margin.Top);
result = true;
}
if (rect.Y < offset.Y)
{
offset = offset.WithY(rect.Y);
result = true;
}
if (rect.Right > offset.X + Viewport.Width)
{
offset = offset.WithX((rect.Right - Viewport.Width) + Child.Margin.Left);
result = true;
}
if (rect.X < offset.X)
{
offset = offset.WithX(rect.X);
result = true;
}
if (result)
{
Offset = offset;
}
System.Diagnostics.Debug.WriteLine($"{targetRect} {offset}");
return result;
}
else
{
return false;
}
}
示例2: BringDescendentIntoView
/// <summary>
/// Attempts to bring a portion of the target visual into view by scrolling the content.
/// </summary>
/// <param name="target">The target visual.</param>
/// <param name="targetRect">The portion of the target visual to bring into view.</param>
/// <returns>True if the scroll offset was changed; otherwise false.</returns>
public bool BringDescendentIntoView(IVisual target, Rect targetRect)
{
if (Child == null)
{
return false;
}
var transform = target.TransformToVisual(Child);
if (transform == null)
{
return false;
}
var rect = targetRect * transform.Value;
var offset = Offset;
var result = false;
if (rect.Bottom > offset.Y + Viewport.Height)
{
offset = offset.WithY((rect.Bottom - Viewport.Height) + Child.Margin.Top);
result = true;
}
if (rect.Y < offset.Y)
{
offset = offset.WithY(rect.Y);
result = true;
}
if (rect.Right > offset.X + Viewport.Width)
{
offset = offset.WithX((rect.Right - Viewport.Width) + Child.Margin.Left);
result = true;
}
if (rect.X < offset.X)
{
offset = offset.WithX(rect.X);
result = true;
}
if (result)
{
Offset = offset;
}
return result;
}
示例3: BringDescendentIntoView
/// <summary>
/// Attempts to bring a portion of the target visual into view by scrolling the content.
/// </summary>
/// <param name="target">The target visual.</param>
/// <param name="targetRect">The portion of the target visual to bring into view.</param>
/// <returns>True if the scroll offset was changed; otherwise false.</returns>
public bool BringDescendentIntoView(IVisual target, Rect targetRect)
{
if (Child == null)
{
return false;
}
var scrollable = Child as ILogicalScrollable;
var control = target as IControl;
if (scrollable?.IsLogicalScrollEnabled == true && control != null)
{
return scrollable.BringIntoView(control, targetRect);
}
var transform = target.TransformToVisual(Child);
if (transform == null)
{
return false;
}
var rect = targetRect * transform.Value;
var offset = Offset;
var result = false;
if (rect.Bottom > offset.Y + Viewport.Height)
{
offset = offset.WithY((rect.Bottom - Viewport.Height) + Child.Margin.Top);
result = true;
}
if (rect.Y < offset.Y)
{
offset = offset.WithY(rect.Y);
result = true;
}
if (rect.Right > offset.X + Viewport.Width)
{
offset = offset.WithX((rect.Right - Viewport.Width) + Child.Margin.Left);
result = true;
}
if (rect.X < offset.X)
{
offset = offset.WithX(rect.X);
result = true;
}
if (result)
{
Offset = offset;
}
return result;
}