Clear spaces from end of line in WPF / XAML

I have an MVVM application that uses a list filled with images. The image line always comes from an object that I cannot change, since it is generated using the edmx model.

To cut the story, I need to enter the following xaml way to trim the space placed at the end of the SQL image path from the string.

<ListBox ItemsSource="{Binding AllImages}" x:Name="listBox1" Width="300" Margin="10,10,0,10"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Image Grid.Column="0" Source="{Binding imagePath}" Height="100" Width="100" /> <TextBlock Grid.Column="1" Text="{Binding imageId}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> 

Is it possible?

+4
source share
2 answers

Use the snapping in the snapping that does the cropping for you.

+8
source

If you do not want to use the converter, you can do it directly in your Property

INotifyChangedProperty Solution

 private string _ImageID; public string ImageID { get { return _ImageID; } set { value = (value == null ? value : value.Trim()); NotifyPropertyChanged("ImageID"); } } 

DependencyProperty Solution

 public static readonly DependencyProperty ImageIDProperty = DependencyProperty.Register("ImageID", typeof(string), typeof(MainWindowViewModel), new PropertyMetadata(string.Empty)); public string ImageID { get { return (string)GetValue(ImageIDProperty); } set { SetValue(ImageIDProperty, value == null ? value : value.Trim()); } } 
+4
source

Source: https://habr.com/ru/post/1390290/


All Articles