Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ComboBox TextWrap Binding

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

like image 708
Prat Avatar asked Feb 16 '23 06:02

Prat


1 Answers

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>
like image 191
Prat Avatar answered Feb 19 '23 21:02

Prat