在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>