Visual.AnchorPoint 속성

정의

시각적 개체의 오프셋에 배치할 시각적 개체의 점입니다. 값은 시각적 개체의 크기와 관련하여 정규화됩니다. 애니메이션 가능.

public:
 property float2 AnchorPoint { float2 get(); void set(float2 value); };
float2 AnchorPoint();

void AnchorPoint(float2 value);
public Vector2 AnchorPoint { get; set; }
var vector2 = visual.anchorPoint;
visual.anchorPoint = vector2;
Public Property AnchorPoint As Vector2

속성 값

Vector2 Vector2

float2

시각적 개체의 오프셋에 배치할 시각적 개체의 점입니다. 값은 시각적 개체의 크기와 관련하여 정규화됩니다.

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10586.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v2.0에서 도입되었습니다.)

예제

using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Composition;
using Windows.UI.Xaml.Hosting;
using System.Numerics;

namespace AnchorPointSample
{
    /// <summary>
    /// Using AnchorPoint to Center a Rectangle
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            this.Loaded += MainPage_Loaded;
        }

        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Get the backing visual for the "CenteredElement" XAML Element
            Visual root = ElementCompositionPreview.GetElementVisual(CenteredElement);
            Compositor compositor = root.Compositor;

            // Create a solid color visual
            SpriteVisual mainVisual = compositor.CreateSpriteVisual();
            mainVisual.Size = new Vector2(200, 200);
            mainVisual.Brush = compositor.CreateColorBrush(Windows.UI.Colors.Blue);

            // Set the anchor point to center the rectangle
            mainVisual.AnchorPoint = new Vector2(0.5f, 0.5f);

            // Insert the rectangle as a child of the XAML element
            ElementCompositionPreview.SetElementChildVisual(CenteredElement, mainVisual);
        }
    }
}

적용 대상