MultiBinding的StringFormat参数问题

2017-05-17 21:44:49来源:cnblogs.com作者:一!雨人点击

在wpf的绑定中,我们会用到多值绑定,如下:

<MultiBinding Mode="OneWay" StringFormat="{3}({0}/{1}):{2}">
        <Binding Path="CurIndex" Mode="OneWay"></Binding>
        <Binding Path="TotalCount" Mode="OneWay"></Binding>
        <Binding Path="CurName" Mode="OneWay"></Binding>
        <Binding Path="AreaName" Mode="OneWay"></Binding>
</MultiBinding>

这里如果

StringFormat="{3}({0}/{1}):{2}"这样写是不能通过编译器的,解决方案是在前面加一组大括号就可以了,如下:

StringFormat="{}{3}({0}/{1}):{2}"

完整绑定如下:

<TextBlock.Text>
          <MultiBinding Mode="OneWay" StringFormat="{}{3}({0}/{1}):{2}">
          <Binding Path="CurIndex" Mode="OneWay"></Binding>
          <Binding Path="TotalCount" Mode="OneWay"></Binding>
          <Binding Path="CurName" Mode="OneWay"></Binding>
           <Binding Path="AreaName" Mode="OneWay"></Binding>
           </MultiBinding>
</TextBlock.Text>

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台