예제 #1
0
 /// <summary>
 /// Sets the <see cref="Visual.CenterPoint"/> property of the <see cref="Visual"/> behind a given <see cref="FrameworkElement"/>
 /// </summary>
 /// <param name="element">The source <see cref="FrameworkElement"/></param>
 /// <param name="x">The center to use on the X axis. If <see langword="null"/>, the center of the <see cref="FrameworkElement"/> will be used</param>
 /// <param name="y">The center to use on the Y axis. If <see langword="null"/>, the center of the <see cref="FrameworkElement"/> will be used</param>
 public static void SetVisualCenterPoint(this FrameworkElement element, double?x, double?y)
 {
     if (double.IsNaN(element.Width) || double.IsNaN(element.Height))
     {
         throw new InvalidOperationException("The target element must have a fixed size");
     }
     element.GetVisual().CenterPoint = new Vector3((float?)x ?? (float)(element.Width / 2), (float?)y ?? (float)(element.Height / 2), 0);
 }