我有一个组合框,我将数据绑定到视图模型。
下拉单元格显示正确,但组合框文本块显示不一样。
这是我的组合框 xaml
<ComboBox x:Name="UserComboBox" ItemsSource="{Binding userInfoViewModel.Users}"
SelectedItem="{Binding userInfoViewModel.SelectedUser, Mode=TwoWay}"
ItemTemplate="{StaticResource UserTemplate}"
ItemContainerStyle="{DynamicResource CustomUserComboBoxStyle}"
HorizontalAlignment="Left" Margin="39.025,217.76,0,186.025" Width="204.975" IsEditable="True" Background="#FFF3F3F3"
BorderBrush="{DynamicResource CustomBorder}"
Height="27.24" >
</ComboBox>
这是我的用户模板
<DataTemplate x:Key="UserTemplate">
<StackPanel FlowDirection="LeftToRight" Orientation="Horizontal">
<TextBlock Text="{Binding Path=InternalNumber}"></TextBlock>
<TextBlock Text="{Binding Path=UserName}" ></TextBlock>
</StackPanel>
</DataTemplate>
和我的 CustomUserComboBoxStyle
<Style x:Key="CustomUserComboBoxStyle" TargetType="{x:Type ComboBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="Padding" Value="3,0,3,0"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsHighlighted" Value="true">
<Setter Property="Background" Value="#646363" />
<Setter Property="Foreground" Value="#FFFFFFFF"/>
<Setter Property="BorderBrush" Value="#646363"/>
</Trigger>
<Trigger Property="IsHighlighted" Value="false">
<Setter Property="Background" Value="#FFF3F3F3" />
<Setter Property="BorderBrush" Value="#FFF3F3F3"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
为什么组合框显示 Digicom.Eventserver.Client.user 而不是名称和编号?