I am having a bit of a trouble when using TextBox in combination with an oblique text.
I took a look at a similar SO question where the control used is actually a TextBlock and increasing the Height
(as suggested) neither solves the problem for TextBox nor fits the needs of my scenario as I need the Height
to be set implicitly based on the Height
of the text inside the TextBox.
Apart from that, I was not able to find any other related questions.
I have the following XAML code:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<TextBox
HorizontalAlignment="Left"
VerticalAlignment="Top"
FontStyle="Normal"
FontSize="50"
Text="Another text">
</TextBox>
</Window>
Everything looks fine until I change the FontStyle
to Oblique
(click on the links below to see the pictures):
I found out the problem is probably caused by TextBoxView inside the TextBox which has its Width
computed in a rather strange way. It seems that a portion of letter reaches outside of its "selection bounds" (when you take a look at the selected text and the Snoop WPF element highlight I am sure you will know what I mean).
As it turns out, adjusting the TextBoxView Width
in Snoop WPF resolves the problem. However, I am not able to achieve the same in XAML.
I could probably work this around by creating a custom template for TextBox, but it certainly seems like an overkill and an awful amount of work for something I would expect to be working properly in the first place.
Did I miss something or is it really so difficult to get it working the right way?
PS: I really need the text to be selectable so using a TextBlock instead of TextBox is out of the question.