Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Unassigned: RichTextBox: Remove wordwrap feature [21850]

$
0
0
Hi,

Is there any way to remove wordwrap feature?

I have wpf application in which there is richtextbox control. I added some multiline text with tabs and spaces into this richtextbox.
If I increase the font all my text formatting is change and a vertical scroll bar appears.

I feel this is caused because of word wrap.

Regards,
Sharda.
Comments: ** Comment from web user: shardaiyer **

Hi,
I have created a sample application.
To reproduce the issue please execute below steps:-
1. Run the application
2. Copy below steps in rich text box.
CodePlex is Microsoft's free open source project hosting site. You can create projects to share with the world, collaborate with others on their projects, and download open source software. Entity Framework is an object-relational mapper that enables .NET developers to work with relational data using domain-specific objects.
3. Select the complete text and increase the font by 24. Vertical scroll will appear.
4. Insert tab in front of every line.
5. Click on save.
6. Click on load. You will observe that formatting is changed.

Below is source code.
MainWindow.xaml

```
<Window x:Class="TryRichTextBoxWPFToolKit.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:wpftoolkit="http://schemas.xceed.com/wpf/xaml/toolkit">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<wpftoolkit:RichTextBox x:Name="PART_RichText"
Width="400"
Height="200"
AcceptsTab="True"
Background="Black"
BorderThickness="0"
CaretBrush="White"
Foreground="White"
HorizontalScrollBarVisibility="Auto"
Text="{Binding Path=RtfDocument,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
VerticalScrollBarVisibility="Auto"
Grid.Row="0">
<wpftoolkit:RichTextBox.TextFormatter>
<wpftoolkit:RtfFormatter/>
</wpftoolkit:RichTextBox.TextFormatter>
<wpftoolkit:RichTextBoxFormatBarManager.FormatBar>
<wpftoolkit:RichTextBoxFormatBar/>
</wpftoolkit:RichTextBoxFormatBarManager.FormatBar>
</wpftoolkit:RichTextBox>
<Button Content="Load" Click="OnClickLoad" Width="50" Height="50" Grid.Row="1"></Button>
<Button Content="Save" Click="OnClickSave" Width="50" Height="50" Grid.Row="2"></Button>
</Grid>
</Window>

```
MainWindow.xaml.cs
```
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;

namespace TryRichTextBoxWPFToolKit
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private string _fileName;

public MainWindow()
{
InitializeComponent();
var documentFolderPath = Directory.GetCurrentDirectory();
_fileName = Path.Combine(documentFolderPath, "temp" + "_rtf.rtf");
this.DataContext = new MainWindowViewModel();
}

private void OnClickLoad(object sender, RoutedEventArgs e)
{
(DataContext as MainWindowViewModel).RtfDocument = string.Empty;
var lines = File.ReadAllText(_fileName);
(DataContext as MainWindowViewModel).RtfDocument = lines;
}

private void OnClickSave(object sender, RoutedEventArgs e)
{
var rtfCode = (DataContext as MainWindowViewModel).RtfDocument;

//Save RTF code in the rtf file in document folder
File.WriteAllText(_fileName, rtfCode);
MessageBox.Show("Save Successful");
(DataContext as MainWindowViewModel).RtfDocument = string.Empty;
}
}
}

```
MainWindowViewModel.cs
```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TryRichTextBoxWPFToolKit
{
public class MainWindowViewModel : INotifyPropertyChanged
{
public string _rtfDocument;

public string RtfDocument
{
get
{
return _rtfDocument;
}
set
{
_rtfDocument = value;
OnPropertyChanged("RtfDocument");
}
}

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(propertyName);
handler(this, e);
}
}
}
}


```
Please let me know your email id. I will send the text application to you.
Regards,
Sharda.


Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>