4

I have the following ComboBox

<ComboBox x:Name="TaskText" Text="{Binding TaskNameBinding}" ItemsSource="{Binding 
    taskList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name" 
    Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="90"/>

I wish to apply Text Wrapping to this combobox and followed to code snippet from the answer here

<ComboBox x:Name="TaskText" ItemsSource="{Binding taskList, ElementName=MainWin}" 
    SelectedValuePath="_id" DisplayMemberPath="_name" Background="Yellow" Padding="0" 
    Margin="0" BorderThickness="0" Width="90">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding TaskNameBinding}" 
                TextTrimming="CharacterEllipsis" />
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

But this template is breaking the binding and the combobox displays no values. Any help would be appreciated

Community
  • 1
  • 1
Prat
  • 495
  • 7
  • 19
  • How is it breaking the `Binding`? What does that mean? What errors are you getting in the `Output` Window in Visual Studio? – Sheridan Sep 16 '13 at 11:19
  • There was nothing being displayed in the window and the error was a property not found on object – Prat Sep 16 '13 at 11:20
  • 1
    yeah sorry, was working on it for 2 days before I posted a question. Sometimes it just strikes you,you know? – Prat Sep 16 '13 at 11:24
  • 1
    I know exactly what you mean... I used to do the same. Often, I would try to simplify the problem so I could post a simplified version here, but then just simplifying the problem would often allow me to find the solution. – Sheridan Sep 16 '13 at 11:26
  • 1
    @Sheridan it is good that he posted it here, because this way other people can profit from the answer – Welcor Oct 29 '19 at 17:25

1 Answers1

8

Figured it out

<ComboBox x:Name="TaskText" Text="{Binding TaskNameBinding}" ItemsSource="{Binding taskList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="90">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock 
                                Text="{Binding _name}" 
                                TextWrapping="Wrap" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
Prat
  • 495
  • 7
  • 19