【问题标题】:Content Alignment in Xamarin Forms does not work?Xamarin 表单中的内容对齐不起作用?
【发布时间】:2015-01-11 16:25:51
【问题描述】:

我在 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 与底部对齐吗? 当我使用控件时,控件具有预期的大小(填充整个可用空间),但内部堆栈布局与顶部对齐。 :(

【问题讨论】:

  • 有没有人在生产中使用 Xamarin.Forms?在当前状态下似乎非常有问题! :(

标签: xamarin.forms


【解决方案1】:

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

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

在您的示例中 - 也许您必须为网格提供正确的行定义和列定义,并将堆栈布局定位在特定的网格单元中。并且 stacklayout 内容的对齐将仅在此单元格内。

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

【讨论】:

    猜你喜欢
    • 2019-01-16
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 2020-04-24
    • 2019-03-01
    • 2021-12-01
    • 2016-02-13
    • 2014-09-27
    相关资源
    最近更新 更多