如何将特定值传递给转换器参数? [英] How to pass specific value to the converter parameter?

查看:105
本文介绍了如何将特定值传递给转换器参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ConverterParameter内发送静态值(例如数字)?

How I send an static value inside ConverterParameter such as a number?

<Label Style="{DynamicResource ListItemDetailTextStyle}" Text="{Binding Information, Converter={StaticResource CutStringConverter}, ConverterParameter={100}}" />

推荐答案

您可能需要然后输入类型.因此,可以这样内联:ConverterParameter={x:Int32 100}.

You probably need to include the type then. So either do it inline like this: ConverterParameter={x:Int32 100}.

或者写得更冗长:

<Label>
     <Label.Text>
         <Binding Path="Information" Converter="{StaticResource CutStringConverter}">
             <Binding.ConverterParameter>
                 <x:Int32>100</x:Int32>
             </Binding.ConverterParameter>
        </Binding>
    </Label.Text>
</Label>

或者,完整地说,向页面(或任何容器)中添加静态资源,例如:

Or, to be complete, add a static resource to your page (or whatever the container is), like:

<ContentPage.Resources>
    <x:Int32 x:Key="IntHundred">100</x:Int32>
</ContentPage.Resources>

并引用:ConverterParameter={StaticResource IntHundred}

这篇关于如何将特定值传递给转换器参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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