You could try to set the data source string Selected application
, set StringFormat when binding to add spaces
and . . .
.
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<ComboBox Name="cb2" Width="400" Height="30" ItemsSource="{Binding List}"
SelectedIndex="{Binding Selected}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name, StringFormat='{}{0}\ ...'}">
</TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Update:
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Window.Resources>
<local:Converter x:Key="converter"/>
</Window.Resources>
<ComboBox Name="cb2" Width="400" Height="30" ItemsSource="{Binding List}"
SelectedIndex="{Binding Selected}" DisplayMemberPath="Name" >
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Converter={StaticResource converter}, RelativeSource={RelativeSource Self}}" Value="IsLastItem">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name, StringFormat='{}{0}\ ...'}" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
Codebehind:
253794-combobx-last-item-style-converter.txt
Update2:
The Code:
256297-withespace.txt
The result:
----------------------------------------------------------------------------
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.