我有一个 ComboBox 定义如下:
<ComboBox Width="200" Height="30" Grid.Column="0" x:Name="ExistingSpeciesComboBox"
ItemsSource="{Binding SpeciesColorCollection}" HorizontalAlignment="Left">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="{Binding Path=Brush}" Stroke="Black" StrokeThickness="1" Height="15" Width="30"/>
<w:WTextBlock Text="{Binding Name}" VerticalAlignment="Center"
Foreground="{StaticResource SmallControlForegroundBrush}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
SpeciesColorCollection 是 ColorObject 类型的 ObservableCollection
Public Class ColorObject
Public Property Name As String
Public Property Brush As Brush
End Class
ComboBox 正确显示集合中的项目,但我的问题是当我尝试从 MultiBinding 中的 ComboBox 获取所选文本时,我收到 ColorObject 而不是名称。如何从 ComboBox 的 WTextBlock 中获取“名称”的值?我用于命令的绑定如下。转换器只返回字符串。
<MultiBinding Converter="{StaticResource mySpeciesSetupConverter}">
<MultiBinding.Bindings>
<Binding ElementName="NewSpeciesName" Path="Text" />
<Binding ElementName="ExistingSpeciesComboBox" Path="Text" />
</MultiBinding.Bindings>
</MultiBinding>