سؤال

I have a ComboBox defined as below:

<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 is an ObservableCollection of type ColorObject

Public Class ColorObject
    Public Property Name As String
    Public Property Brush As Brush
End Class

The ComboBox displays the items from the collection correctly but my problem is when I try to get the selected text from the ComboBox in a MultiBinding, I receive ColorObject instead of the name. How do I go about getting the value of the "Name" from within the WTextBlock of the ComboBox? The binding that I am using for my command is below. The converter is only returning strings.

<MultiBinding Converter="{StaticResource mySpeciesSetupConverter}">
    <MultiBinding.Bindings>
        <Binding ElementName="NewSpeciesName" Path="Text" />
        <Binding ElementName="ExistingSpeciesComboBox" Path="Text" />
    </MultiBinding.Bindings>
 </MultiBinding>
هل كانت مفيدة؟

المحلول

<MultiBinding Converter="{StaticResource mySpeciesSetupConverter}">
    <MultiBinding.Bindings>
        <Binding ElementName="NewSpeciesName" Path="Text" />
        <Binding ElementName="ExistingSpeciesComboBox" Path="SelectedItem.Name" />
    </MultiBinding.Bindings>
</MultiBinding>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top