【问题标题】:Xamarin changing binding context value during runtimeXamarin 在运行时更改绑定上下文值
【发布时间】:2022-06-10 22:01:07
【问题描述】:

请问题可能很有趣,一点也不有趣或令人困惑!但我想要的简单目标是在运行时更改 xamarin.forms 中绑定上下文的值!!

IvalueConverter

class LoginFrameHeight : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return (double)value / 1.9;
    }

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

资源字典

    <ResourceDictionary>
        <local:LoginFrameHeight x:Key="frameHeight"/>
    </ResourceDictionary>

设置框架高度

   <Frame CornerRadius="15"
      HeightRequest="{Binding Source={x:Reference frame},
      Path=Height,Converter={StaticResource frameHeight}}" Padding="0"></Frame>

代码运行良好!我的问题是我有大约 三 (3) 帧 可以使用相同的流程应用不同的 HeightRequested!是否可以在 IvalueConverter 期间更改 (1.9) 运行时,以便我可以使用相同的类 LoginFrameHeight 而不是为框架创建不同的类?

【问题讨论】:

  • 比例因子从何而来?它是绑定对象的属性,还是每个帧的硬编码值,还是其他什么?

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


【解决方案1】:

答案是“是”,您可以在这里使用 ConverterParameter 快速参考:This official documentation will show more

例如:&lt;Label Text="{Binding Red,Converter={StaticResource doubleToInt}, ConverterParameter=255, StringFormat='Red = {0:X2}'}" /&gt;

【讨论】:

    猜你喜欢
    • 2017-09-23
    • 2014-07-26
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 2012-06-04
    • 1970-01-01
    相关资源
    最近更新 更多