如何将特定值传递给转换器参数?

时间:2017-07-29 15:49:49

标签: xaml xamarin xamarin.forms

我如何在ConverterParameter中发送静态值,例如数字?

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

1 个答案:

答案 0 :(得分:8)

您可能需要包含该类型。所以要么像这样内联: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>

或者,要完成,请向页面添加静态资源(或容器的任何内容),例如:

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

并参考:ConverterParameter={StaticResource IntHundred}

相关问题