Answer the question
In order to leave comments, you need to log in
WPF ComboBox length values?
Good afternoon! I can't find a solution to the problem. The question is: I'm loading values for a combobox and some values can be very long and start to look ugly as a long selection menu. I can’t figure out how to limit the number of displayed characters (or the width of the displayed area), so that what doesn’t fit is cut off, but when selected in the combobox value, it is displayed completely. I am attaching a picture to make it clearer what the problem is.
Answer the question
In order to leave comments, you need to log in
Make a converter that will cut the strings to the length you need. And use it when deriving values from the model.
<ComboBox ItemsSource="{Binding}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource TrimValueConverter}}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
class TrimValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null)
{
string s = value.ToString();
return s.Substring(0, 100);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question