【问题标题】:Xamarin Forms RowDefinition height binding via converter set height autoDXamarin Forms RowDefinition 高度绑定通过转换器设置高度 autoD
【发布时间】:2018-10-24 22:17:51
【问题描述】:

目前我想将我的Height 属性绑定到Rowdefinition 上的Grid。如果我的ViewModel 上的属性IsOnline 设置为true,我想显示该行。

将数字绑定为Height 完全没有问题,我只是想知道如何将它绑定到Auto

我的观点:

<Grid.RowDefinitions>
    <RowDefinition/>
    <RowDefinition/>
    <RowDefinition Height="{Binding IsOnline, Converter={StaticResource HeightConverter}}"/>
</Grid.RowDefinitions>

我的转换器HeightConverter:

public class HeightConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is bool)
        {
            if ((bool)value)
            {
                return "Auto";
            }
        }

        return 0;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

【问题讨论】:

    标签: c# wpf xamarin xamarin.forms binding


    【解决方案1】:

    检查GridLength Struct,它具有Auto、Star 等属性。您可以将它们用作IValueConverter 的返回值。

    【讨论】:

    • RowDefinition 的 height 属性也得到了 Auto。如果我不绑定它,它可以正常工作......在绑定中,我无法使用它。
    • 所以当您从转换器返回 GridLength.Auto 时,它不起作用?我没有收到你的最后评论...
    • 哦,我的错,我不知何故误解了你的答案。现在工作正常!
    • 没问题,我编辑了我的答案,以便更容易理解我的意思。
    猜你喜欢
    • 1970-01-01
    • 2011-01-25
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    • 1970-01-01
    • 2020-10-18
    • 2023-03-20
    相关资源
    最近更新 更多