【问题标题】:How to set ConvertParameter in binding in UWP如何在 UWP 的绑定中设置 ConvertParameter
【发布时间】:2021-12-26 10:50:40
【问题描述】:

我有一个场景,我必须通过转换器中的绑定来比较传递的枚举值并返回可见性,我想在绑定表达式中传递转换参数,但是在 UWP 中我们没有 x:Static,那么如何我可以这样做吗

我已经尝试过这些东西

Visibility="{x:Bind   vm.ControlState, 
                        Mode=OneWay,
                        Converter={StaticResource enumToVisibilityConverter}, 
                        ConverterParameter={x:Bind enums:TextControlState.Controls}}"

它在编译期间抛出错误,说嵌套的 x:Bind 是不允许的

Visibility="{Binding   ControlState, 
            Mode=OneWay,
            Converter={StaticResource enumToVisibilityConverter}, 
            ConverterParameter={x:Bind enums:TextControlState.Controls}}"

它在运行时抛出错误,说不能分配绑定表达式

【问题讨论】:

    标签: c# mvvm uwp uwp-xaml


    【解决方案1】:

    但是在 UWP 中我们没有 x:Static,那我该怎么做呢

    正如你上面提到的,我们不能在uwp平台上使用x:Static,但是我们可以使用StaticResource来代替。

    例如

    <Page.Resources>
        <local:TextControlState x:Key="ConState">Controls</local:TextControlState>
    </Page.Resources>
    
    
    
    Visibility="{x:Bind  vm.ControlState, 
                        Mode=OneWay,
                        Converter={StaticResource enumToVisibilityConverter}, 
                        ConverterParameter={StaticResource ConState}}"
    

    【讨论】:

    • 它正在工作,谢谢,但有没有其他方法,因为现在我也已经在 XML 中创建了所有枚举值
    猜你喜欢
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 2017-03-23
    • 2016-12-01
    • 2011-06-07
    • 1970-01-01
    相关资源
    最近更新 更多