我有一个TextBlock绑定到我的模型的Integer属性。 TextBlock int属性将其计数从0增加到99.我首先在ListView中显示TextBlocks 0-9。TextBlock绑定
如果有超过10个TextBlocks,我希望编号为0-9的前10个TextBlocks显示为00,01,02 .. 09。我可以使用WPF中的string.Format
方法来实现此行为。但是如果少于10个TextBlocks,它们应该编号为0,1,2-9。
我该如何实现这种行为?我可以使用MultiBinding Converter吗?如果是的话,帮我一个样本。
下面是代码:
<ListView ItemsSource= "{Binding}"> <!-- Binding to a collection which has the Tag Id property -->
<Grid x:Name="TagNum_grid" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="1,3,0,0" Grid.Column="1" >
<TextBlock x:Name="DefaultIDtextblock" Margin="1,0" Text="{Binding Path=TagID}" TextWrapping="Wrap" Foreground="#FFA0A0A0" />
</Grid>
</ListView>
伟大的作品...非常感谢阿迪!如果(itemCount> 10 && tagId <10),我在这里为转换器中的检查做了一个小改动。 – Jack