【发布时间】:2010-12-15 03:56:33
【问题描述】:
我有一个ListBox:
<ListBox x:Name="HistogramListBox" Grid.Column="1" Margin="8,2,8,0"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Template="{StaticResource HistogramListBoxControlTemplate}"
ItemContainerStyle="{StaticResource HistogramListBoxItem}"
ItemTemplate="{DynamicResource BucketTemplate}" />
使用DataTemplate 反过来又使用ValueConverter 来确定@987654325@ 的高度:
<DataTemplate x:Key="BucketTemplate">
<StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Bottom">
<Rectangle Grid.Row="0" StrokeThickness="1" VerticalAlignment="Bottom"
Stroke="{Binding ElementName=MainElement, Path=BucketStroke}"
Fill="{Binding ElementName=MainElement, Path=BucketFill}" >
<Rectangle.Height>
<MultiBinding Converter="{StaticResource HistogramValueToPercentageConverter}">
<Binding Mode="OneWay" Path="ItemCount" />
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:Histogram}}" />
</MultiBinding>
</Rectangle.Height>
</Rectangle>
</StackPanel>
</Grid>
</StackPanel>
</DataTemplate>
ListBoxItemsSource 是一个int[]。
当我执行代码时,它说在 Int32 上找不到“ItemCount”。我以为它从ListBox 得到了项目计数(我显然错了)。
谁能告诉我如何让我的ValueConverter 知道我在做什么。
谢谢
丹
【问题讨论】:
标签: wpf data-binding binding listbox ivalueconverter