How to change tab width in silverlight TextBox

The width of the Tab character (\ t) in a silverlight TextBox is not 4 spaces or 8 spaces. He is too short. Can I change the width of the TAB character (\ t) displayed in a Silverlight TextBox?

Please note that I want to avoid replacing TAB with spaces. Any ideas on how to do this?

+4
source share
3 answers

Silverlight does not allow you to change the length of a tab character in a TextBox.

If you read a line (from a file or something else) and set the text for it, then if you look at your text property, you will see an escaped tab (\ t). Search \ t easy

TabTextBox.Text = TabTextBox.Text.Replace("\t", " "); 

Thus, this will replace all tabs with four spaces.

In addition to clicking a tab, TextBox will not insert text. He will focus on the next UIElement in the parent UIElement.

+2
source

Or maybe at the tab key event, add a string literal to the text box. Similar to what MyK offers.

+1
source

If you are trying to display this, write a converter. syntax - just take an example, rename it something like "tabstoptexttospacedtextconverter", add a link to your local controls in app.xaml, then create an instance and give it the name x :, Bind the data for your text box and assign it a new converter.

This will be a bit of a hassle, because you will need to determine the appropriate width of the final TB screen, and then probably use the converter configurator to do this job. But the long story is short, broken by \ t, then foreach (the str line in splitSourceText) does something like this:

 for (int i = 0; i < (str.Length % 8 > 0 ? str.Length % 8 : 8); i++) str+= " "; 

You can limit the characters in arrays of separated strings to a parameter or first split into \ r \ n.

+1
source

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


All Articles