Xamarin表单-在XAML中使用TranslateTo的等效项

时间:2019-02-08 11:29:21

标签: c# xaml xamarin.forms

如果我想在屏幕上将按钮移动到与页面上另一个控件的高度相同的距离,我可以这样做:

this.myControl.TranslateTo(20, - this.myOtherControl.Height);

在XAML中有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

您的情况是否类似于下面的屏幕截图?

enter image description here

您要实现此屏幕截图吗?

enter image description here

您可以使用TranslationY="{ Binding Path=TranslationY ,Source={x:Reference btn1}}"来实现。

<StackLayout Orientation="Horizontal"  VerticalOptions="Start">
    <StackLayout Orientation="Horizontal" HeightRequest="100"    Padding="20,0,0,0">
        <Button x:Name="btn1"  Text="Aqua" HeightRequest="60" WidthRequest="50" TranslationY="23" />
     </StackLayout>
    <StackLayout Orientation="Horizontal" HeightRequest="100"    Padding="20,0,0,0">
        <Button HeightRequest="60" WidthRequest="50" Text="llll" TranslationY="{ Binding Path=TranslationY ,Source={x:Reference btn1}}"/>
    </StackLayout>
</StackLayout>