什么是<ColumnDefinition/>在 Xamarin Forms 中使用 for 并且可以用值设置替换吗? [英] What is the <ColumnDefinition /> used for in Xamarin Forms and can it be replaced with a value setting?

查看:30
本文介绍了什么是<ColumnDefinition/>在 Xamarin Forms 中使用 for 并且可以用值设置替换吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,我想将 ColumnDefinition 转换为在第一行使用新语法.

I have this code and I would like to convert the ColumnDefinition to use the new syntax where it's on the first line.

在这种情况下,有人可以向我解释什么是 用于:

Can someone explain to me in this case what is <ColumnDefinition /> used for:

<Grid Margin="5,5,5,0" >

    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition Width="50" />
    </Grid.ColumnDefinitions>

    <Grid.GestureRecognizers>
        <TapGestureRecognizer Tapped="TitleTapped" />
    </Grid.GestureRecognizers>

    <t:FaqTemplate
        HorizontalOptions="Start"
        Text="{Binding Source={x:Reference _accordion_view_123}, Path=Title}"
        VerticalOptions="CenterAndExpand" />

    <ContentView
        x:Name="_indicatorContainer"
        Grid.Column="1"
        Content="{Binding Source={x:Reference _accordion_view_123}, Path=IndicatorView}"
        HorizontalOptions="End"
        VerticalOptions="Start" />
</Grid>

推荐答案

使用新语法,将转化为:

Using the new syntax, that would translate to:

<Grid ColumnDefinitions="*, 50">

有关新语法的完整规范,您可以阅读以下内容:https://github.com/microsoft/microsoft-ui-xaml/issues/673

For the complete specs on the new syntax, you can read this: https://github.com/microsoft/microsoft-ui-xaml/issues/673

基本上, 等价于 (*Width 属性的默认值).

Basically, <ColumnDefinition /> is the equivalent of <ColumnDefinition Width="*" /> (* is the default value for the Width property).

列的宽度可以用三种方式表示:

The width of a column can be expressed in 3 ways:

  • Auto 表示该列将在可用空间内根据内容自动调整大小
  • 50 这样的绝对值,在这种情况下,列的宽度为 50 个与密度无关的像素
  • * 实际上相当于 1*.* 允许您按比例分割可用空间.例如,如果您有带有 1* 的 A 列和带有 3* 的 B 列,则 A 列将占据 25%(4 个中的 1 个),B 列将占据 75%(第 3 个,共 4 个).
  • Auto means that the column will automatically size itself based on content, within the available space
  • absolute values like 50, in that case the column will be 50 density-independent pixels wide
  • or * which is actually the equivalent of 1*. * allows you to split the available space proportionally. For example, if you have column A with 1* and column B with 3*, column A will occupy 25% (1 of 4) and column B will occupy 75% (3 of 4).

在您的特定情况下,第二列的固定值为 50,因此您的第一列具有 * 宽度将占用 100% 的剩余宽度50 减去.

In your particular case, the second column has a fixed value of 50, so your first column with * width will take up 100% of the remaining width after the 50 is subtracted.

您可以在此处查看不同的示例:

You can check out different examples here:

这篇关于什么是&lt;ColumnDefinition/&gt;在 Xamarin Forms 中使用 for 并且可以用值设置替换吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆