Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ignoring while preserving line breaks in WPF TextBox
- <Grid Background="AliceBlue">
- <Grid.RowDefinitions>
- <RowDefinition Height="100"/>
- <RowDefinition Height="100"/>
- </Grid.RowDefinitions>
- <TextBox x:Name="FirstTextBox"
- AcceptsReturn="True"
- TextWrapping="Wrap"
- Text="{Binding MyString}"
- Width="150"/>
- <TextBox x:Name="SecondTextBox"
- Grid.Row="1"
- AcceptsReturn="False"
- TextWrapping="NoWrap"
- Text="{Binding MyString}"
- VerticalAlignment="Top"/>
- </Grid>
- public class IgnoreLinebreaksConverter : IValueConverter
- {
- private const string Sub = " u200B";
- private const string Lb = "rn";
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- var s = (string)value;
- return string.IsNullOrEmpty(s) ? s : Regex.Replace(s, Lb, Sub);
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- var s = (string)value;
- return string.IsNullOrEmpty(s) ? s : Regex.Replace(s, Sub, Lb);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment