FixedPage.SetLeft(UIElement, Double) 方法

定义

设置某元素的左侧与其父 Canvas 的左侧之间的距离。

public:
 static void SetLeft(System::Windows::UIElement ^ element, double length);
public static void SetLeft (System.Windows.UIElement element, double length);
static member SetLeft : System.Windows.UIElement * double -> unit
Public Shared Sub SetLeft (element As UIElement, length As Double)

参数

element
UIElement

要在其上设置左侧偏移量的元素。

length
Double

元素的左侧与其父画布的左侧之间的新距离。

示例

以下示例演示如何使用 SetLeft 方法。

// --------------------- CreateFifthPageContent -----------------------
/// <summary>
///   Creates the content for the fifth fixed page.</summary>
/// <returns>
///   The page content for the fifth fixed page.</returns>
private PageContent CreateFifthPageContent()
{
    PageContent pageContent = new PageContent();
    FixedPage   fixedPage   = new FixedPage();
    UIElement   visual      = CreateThirdVisual(false);

    FixedPage.SetLeft(visual, 0);
    FixedPage.SetTop(visual, 0);

    double pageWidth = 96 * 8.5;
    double pageHeight = 96 * 11;

    fixedPage.Width = pageWidth;
    fixedPage.Height = pageHeight;

    fixedPage.Children.Add((UIElement)visual);

    Size sz = new Size(8.5 * 96, 11 * 96);
    fixedPage.Measure(sz);
    fixedPage.Arrange(new Rect(new Point(), sz));
    fixedPage.UpdateLayout();

    ((IAddChild)pageContent).AddChild(fixedPage);
    return pageContent;
}// end:CreateFifthPageContent()
' --------------------- CreateFifthPageContent -----------------------
''' <summary>
'''   Creates the content for the fifth fixed page.</summary>
''' <returns>
'''   The page content for the fifth fixed page.</returns>
Private Function CreateFifthPageContent() As PageContent
    Dim pageContent As New PageContent()
    Dim fixedPage As New FixedPage()
    Dim visual As UIElement = CreateThirdVisual(False)

    FixedPage.SetLeft(visual, 0)
    FixedPage.SetTop(visual, 0)

    Dim pageWidth As Double = 96 * 8.5
    Dim pageHeight As Double = 96 * 11

    fixedPage.Width = pageWidth
    fixedPage.Height = pageHeight

    fixedPage.Children.Add(CType(visual, UIElement))

    Dim sz As New Size(8.5 * 96, 11 * 96)
    fixedPage.Measure(sz)
    fixedPage.Arrange(New Rect(New Point(), sz))
    fixedPage.UpdateLayout()

    CType(pageContent, IAddChild).AddChild(fixedPage)
    Return pageContent
End Function ' end:CreateFifthPageContent()

注解

子元素的左偏移量不会影响父画布的大小。

如果在同一元素上同时指定了左偏移量和右偏移量,则左偏移量优先。

将左偏移量设置为百分比时,百分比值基于父画布的宽度。

适用于

另请参阅