如何检测StackLayout的Y位置

时间:2017-11-15 04:22:24

标签: xamarin xamarin.forms

我正在使用机制通过手势移动Stacklayout。是否有另一个事件检测到StackLayout的Y位置变化?这意味着我想在StackLayout位置被向上或向下平移时捕获。

   <StackLayout x:Name="bottomDrawer" BackgroundColor="Olive" AbsoluteLayout.LayoutBounds="0.5,1.00,0.9,0.04" AbsoluteLayout.LayoutFlags="All">
        <StackLayout.GestureRecognizers>
            <PanGestureRecognizer PanUpdated="PanGestureHandler" />
        </StackLayout.GestureRecognizers>
</StackLayout>

1 个答案:

答案 0 :(得分:1)

PropertyChanging上有PropertyChangedBindableObject个事件(StackLayout层次结构中的一个类)。

因此,您可以绑定YHeight和/或LayoutBounds属性上的更改。

使用事件的示例:

aStackLayoutObject.PropertyChanging += (sender, e) =>
{
    switch (e.PropertyName)
    {
        case "Y":
            Log.WriteLine($"{e.PropertyName} : {(sender as StackLayout).Y}");
            break;
        case "Height":
            Log.WriteLine($"{e.PropertyName} : {(sender as StackLayout).Height}");
            break;
        case "LayoutBounds":
            Log.WriteLine($"{e.PropertyName}";
            break;
};

aStackLayoutObject.PropertyChanged += (sender, e) =>
{
    switch (e.PropertyName)
    {
        case "Y":
            Log.WriteLine($"{e.PropertyName} : {(sender as StackLayout).Y}");
            break;
        case "Height":
            Log.WriteLine($"{e.PropertyName} : {(sender as StackLayout).Height}");
            break;
        case "LayoutBounds":
            Log.WriteLine($"{e.PropertyName}";
            break;
};