首页 文章

Xamarin表单中的内容对齐不起作用?

提问于
浏览
1

我在Xamarin Forms中有一个简单的自定义磁贴控件,我无法让内部对齐工作,就像我在MS Xaml中所期望的那样 . (关于Xamarin.iOS(适用于iPad!))

<ContentView.Content>

    <Grid x:Name="LayoutGrid" BindingContext="{x:Reference tile}" BackgroundColor="{Binding Color}">
        <Grid.GestureRecognizers>
            <TapGestureRecognizer Tapped="ExecuteCommandOnTapped" />
        </Grid.GestureRecognizers>

        <StackLayout HorizontalOptions="Start" VerticalOptions="End" BackgroundColor="Aqua" Orientation="Vertical">
            <Label x:Name="AdditionalDescription" Text="{Binding AdditionalText}"   TextColor="{x:Static local:AppColors.AppBackground}" VerticalOptions="End" HorizontalOptions="Start" XAlign="End" YAlign="End" Font="32" /> 
            <Label x:Name="Description"           Text="{Binding Text}"             TextColor="{x:Static local:AppColors.AppBackground}" VerticalOptions="End" HorizontalOptions="Start" XAlign="End" YAlign="End" Font="Bold, 32" />   
        </StackLayout>
    </Grid> 

</ContentView.Content>

是否有任何技巧可以将Inner Stacklayout与底部对齐?当我使用控件时,控件具有预期的大小(填充整个可用空间),但内部堆栈布局与顶部对齐 . :(

1 回答

  • 0

    我遇到了与StackLayout类似的问题,不得不切换到Grid . 使用Grid,我能够利用行/列属性来正确定位我的子控件 .

    -------------------------------------------------- - - - - - -编辑 - - - - - - - - - - - - - - - - - - - -----------------------刚才我发现对齐确实有效但是如果布局在网格中,那么它的效果就在网格的特定单元格内而不是完整的网格 .

    在您的示例中 - 也许您必须为网格提供正确的rowdefinition和columndefintion,并将stacklayout放置在特定的网格单元格中 . stacklayout内容的对齐仅在此单元格内 .

    好读 - http://blog.tpcware.com/2014/09/xamarin-xaml-vs-microsoft-xaml-the-devil-is-in-the-details/ . 您可以运行博客中给出的示例,并查看alignment属性是否正常工作 .

相关问题