1

Windowsメトロアプリ:

ListViewを構成するアイテム(またはセル)の中心を見つける方法が必要です。例:ListViewにデータを入力するスタックパネル内にImageとTextBlockがある場合、そのスタックパネルまたはそれに含まれるオブジェクトまたはビューの中心が必要です。(Windows 8の新機能)よろしくお願いします。

4

1 に答える 1

0

要素の中心点を示すコードを次に示します。一般的な FrameworkElement を使用するため、ListView、StackPanel、またはその他のコントロールを渡すことができます。

    /// <summary>
    ///  Gets the center point of any element 
    /// </summary>
    private Point GetCenterPoint(FrameworkElement element)
    {
        GeneralTransform buttonTransform = element.TransformToVisual(null);

        // This gives the point in the upper left-hand corner of the element.  
        Point topLeftPoint = buttonTransform.TransformPoint(new Point());

        // Now get the center point.
        Point centerPoint = new Point();
        centerPoint.X = topLeftPoint.X + element.ActualWidth / 2;
        centerPoint.Y = topLeftPoint.Y + element.ActualHeight / 2;

        return centerPoint;
    }

お役に立てれば!

于 2012-07-26T14:27:57.790 に答える