【问题标题】:How to dynamically remove values from Grid in XAML?如何从 XAML 中的 Grid 中动态删除值?
【发布时间】:2016-08-23 15:58:00
【问题描述】:

我是 Xamarin 的新手。

现在我已经在 XAML 中实现了一个网格,有 1 行 5 列。

期望就像,当第 3 列中的元素没有任何值要显示(null 或空)时,它将被删除,第 4 列元素到第 3 列,第 5 列元素到第 4 列。

这是如何实现的?

非常感谢。

【问题讨论】:

  • 考虑使用 ListView 或 StackLayout。

标签: xaml xamarin xamarin.ios xamarin.android xamarin.forms


【解决方案1】:

您可以更改Height 属性以隐藏RowDefinition 中的Grid 行。

隐藏一行:

<Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="*" />
    <RowDefinition Height="100" />
    <RowDefinition Height="0" />   <-- this row is hidden-->
</Grid.RowDefinitions>

显示所有行:

<Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="*" />
    <RowDefinition Height="100" />
    <RowDefinition Height="*" />   
</Grid.RowDefinitions>

您还可以将Height 绑定到您的 ViewModel 的属性。

public GridLength GridRowHeight { get; set; }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 2018-01-13
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多