【发布时间】:2012-11-16 18:30:35
【问题描述】:
我的员工列表中的每一项都有Post 属性。此属性为Int64 类型。另外,我有一些 ObservableDictionary<Int64,String> 作为静态属性。每个员工必须通过其键显示String 值。
Employe项的DataTemplate(我删除了多余的):
<DataTemplate x:Key="tmpEmploye">
<Border BorderThickness="3" BorderBrush="Gray" CornerRadius="5">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Path=Post}"/>
</StackPanel>
</Border>
</DataTemplate>
但此代码显示的是 Int64 值,而不是 String。获取静态字典的字符串:
"{Binding Source={x:Static app:Program.Data}, Path=Posts}"
我知道如何解决ComboBox 的问题,但我不知道TextBlock 的问题。对于ComboBox,我写了它(它工作正常):
<ComboBox x:Name="cboPost" x:FieldModifier="public" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Margin="2" Grid.ColumnSpan="2"
ItemsSource="{Binding Source={x:Static app:Program.Data}, Path=Posts}" DisplayMemberPath="Value"
SelectedValuePath="Key"
SelectedValue="{Binding Path=Post, Mode=TwoWay}">
</ComboBox>
但是对于TextBlock,我该如何解决呢?
【问题讨论】:
-
@Blam 通知字典更改。它的签名:
ObservableDictionary<TKey,TValue> : NotifyPropertyChangedClass, INotifyCollectionChanged, IDictionary<TKey, TValue> where TKey: IEquatable<TKey>.