WPF consuming much time to paste large texts to RichTextBox from clipboard - c#

I copied roughly a 200,000 length text to the Clipboard.
And I pasted it to RichTextBox by using shortcut key Ctrl V.
My pc couldn't load it..
But, when I pasted it to a TextBox, it worked well.
Can I ask you what problem is?
Here is my code snippet.
<RichTextBox Grid.Row="1" x:Name="에디터"
AcceptsTab="True" AcceptsReturn="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
PreviewMouseLeftButtonUp="에디터_PreviewMouseLeftButtonUp"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
Margin="5"
>
<FlowDocument Name="editFlow" >
<Paragraph>
여기에 텍스트를 붙여 넣으세요
</Paragraph>
</FlowDocument>
</RichTextBox>

You cannot do it and you should not do it. WPF controls aren't designed to work with that kind of data(hence it freezes).Lets say even if you had succeded in adding that data in RTB the scrollbars would be useless as there would be very little data to display.Imagine the pains you will have when you have to locate a line in the text using scrollbar (it could take minutes...).
So the solution is you need to rethink what you are doing and maybe change your logic.

Related

Any way to load an online image into a richtextbox

I am trying to set an image into a richtextbox.
Can this be done and if so how?
Will I have to use an online textbox and load it into my form using the webbrowser, such as with monaco?
Using the properties menu, I do not see anything about images in the richtextbox, only backcolor, so I tried changing the backcolor to "transparent" because I thought of putting an imagebox under it and setting the link of the image there(say this one: https://media.tenor.com/images/cdcf2410001a5c02bcd371d13743aa57/tenor.gif)
Can anyone help me with this?
In WPF, you can add a BlockUIContainer to the document of your richtextbox. This allows you to input an IElement and display it as part of the document. This is great because that means you can input a picture here aswell.
https://learn.microsoft.com/en-us/dotnet/api/system.windows.documents.blockuicontainer?view=netframework-4.8
Sample:
<RichTextBox HorizontalAlignment="Center" Height="100" VerticalAlignment="Center" Width="100" BorderBrush="Gray">
<FlowDocument>
<BlockUIContainer>
<!-- Here you can input any wpf controls, like the Image control. -->
<Image Height="100" Width="100" Source="C:\Some\Image.png" Stretch="Fill"/>
</BlockUIContainer>
</FlowDocument>
</RichTextBox>
Here's an stackoverflow answer that shows how to add an image from the web:
Showing image in WPF using the URL link from database

How do I reduce the line spacing in XCeed WPF Extended Toolkit Richtextbox

I am using the WPF Extended Toolkit Richtextbox to display simple text. But the lines are widely separated rather than one after the other. Indentation appears to be working OK. It's just that 5 lines of text takes up a lot of space. I tried setting Margin="0." I cannot find a property to set such as "Line Spacing" to set.
<tools:RichTextBox Grid.Row="3"
Grid.Column="1"
Text="{Binding Procedure}"
Margin="0"
ScrollViewer.VerticalScrollBarVisibility="Auto"
BorderBrush="Gray"
BorderThickness="2"
Padding="0"
AcceptsReturn="True"
AcceptsTab="True"
AllowDrop="True"
AutoWordSelection="True"
>
<tools:RichTextBox.TextFormatter>
<tools:PlainTextFormatter/>
</tools:RichTextBox.TextFormatter>
</tools:RichTextBox>
The Document property can not be set with a binding.
Line spacing cannot be formatted using the rtf header with the Text attribute in the extended wpf richtextbox. Use the Block.LineHeight attribute instead. It has to be about 130-150% of the font size to work.
<xctk:RichTextBox Block.LineHeight="20"/>

WPF- Cut-off issue in WrapPanel

when i use more than one controls inside the wrap Panel if any control contains lengthy text (more than the window size) cut-off is happening. (See the image)
I have two textblocks and one button control.
<Grid>
<WrapPanel>
<TextBlock Text="Very long Text Message contains long text for testing " FontWeight="Bold"></TextBlock>
<Button Content="sample Text"></Button>
<TextBlock Text="sample Text textblock"></TextBlock>
</WrapPanel>
</Grid>
the cut-off happens for first text block. i want wrap to next line if the text contains more characters.
help me to solve the issue. thanks in advance.
You need the attribute TextWrapping="Wrap" in your textbox
<TextBlock
Text="Very long Text Message contains long text for testing "
FontWeight="Bold"
TextWrapping="Wrap">
</TextBlock>
Are you trying to make a single paragraph that wraps? If so, then WrapPanel isn't actually what you want.
WrapPanel takes UI elements (rectangular chunks of real estate) and lays them out left-to-right, top-to-bottom. You could enable wrapping in your first TextBlock, but then it'll take up a rectangle of screen space that's two lines high. Because the TextBlock fills that entire rectangle, the button will actually appear under it, rather than to the right of the bold words "for testing ".
If you want to make the whole thing flow like a paragraph, you don't want to use UI elements (which are always rectangular chunks); you want to use text elements (which flow in paragraphs).
The way to get text elements into your XAML is to wrap them in a TextBlock. Try this:
<Grid>
<TextBlock TextWrapping="Wrap">
<Bold>
<Run Text="Very long Text Message contains long text for testing " />
</Bold>
<Button Content="sample Text"></Button>
sample Text textblock
</TextBlock>
</Grid>
Note that I wrapped the first chunk of text in a <Run> element -- otherwise the trailing space would be ignored (assumed to be whitespace in your XAML document). The second chunk of text didn't have leading or trailing spaces, so I just put it directly inline.
This answer has a bit more about the difference between the "controls" and "text" sides of XAML.

AccessText TextWrapping not working with CheckBox

I am trying to implement a TextWrapping feature onto the text that is displayed in a CheckBox. I am using the second method in this walk through.
I have created a completely blank program to test this. I would like to make it so that, when text inside the checkBox is larger than the allowed width, it moves the excess text to the next line under checkBox.
This is my xaml:
<Grid Width="100">
<CheckBox>
<AccessText TextWrapping="Wrap"
Text="This is a really long sentence that needs to create a new line." ... />
</CheckBox>
</Grid>
The walk through uses this method to implement the result that I am looking for. Why isn't this working for me, and how do I implement it correctly?
This is what my output is:
Updates: TextWrapping changed to "Wrap"; Width removed; output updated

how to add emoticon in RichTextBox in WPF [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how to add emoticons(smileys) into WPF richtext box
Now,I want to know , how to add emoticon in RichTextBox in WPF.
For example: when I type hi :) , it will return as image(smile image) in RichTexBox.
I hope , you will help me. if anyone know the solution or example code
Thanks
There isn't a prebuilt solution for this, but, as you're using WPF, you can either react to change of the text inside the RichTextBox via the TextChanged event or via your PropertyChanged -if it's MVVM-.
Once you know text changed you give it a pass by using a simple search (there are way better ways to do this parsing, but for the sake of a simple example just use a simple string search). If you find the text you want, I mean, the token corresponding your smiley hi :) then you can insert the image on that position by playing with the FlowDocument inside the RichTextBox
Before parsing
<RichTextBox>
<FlowDocument>
<Paragraph>
<Run>Hello :) world!</Run>
</Paragraph>
</FlowDocument>
</RichTextBox>
After parsing
<RichTextBox>
<FlowDocument>
<Paragraph>
<Span>
<Run Text="Hello"/>
<Image Width="16" Source="Your emoticon source"/>
<Run Text=" world"/>
</Span>
</Paragraph>
</FlowDocument>
</RichTextBox>
That should give you an idea of how to begin.

Categories

Resources