我的richtextbox有一個奇怪的問題。 我想檢測時,文本是粗體,斜體等WPF富文本框下劃線
E.g
if (richTextBox.Selection.GetPropertyValue(TextElement.FontStyleProperty).ToString() == "Italic") // Pochylenie
{
heremycode
}
如果我們使用
MessageBox(richTextBox.Selection.GetPropertyValue(TextElement.FontStyleProperty).ToString());
我得到斜體。我想要做exacly同樣用下劃線和刪除,因爲我不能用
TextBlock.TextDecorationsProperty.ToString()
,
,因爲我只得到我認爲方法的名字嗎? Nothink像「斜體」,或「粗體」只是「FontStyleProperty」。
private void richTextBox_SelectionChanged(object sender, RoutedEventArgs e)
{
....
if (richTextBox.Selection.GetPropertyValue(TextElement.FontStyleProperty).ToString() == "Italic"
{
backgroundP.Stroke = Brushes.Black;
backgroundP.Fill = Brushes.LawnGreen;
p = true;
}
TextRange selectionRange = new TextRange(richTextBox.Selection.Start, richTextBox.Selection.End);
if (selectionRange.GetPropertyValue(Underline.TextDecorationsProperty).Equals(TextDecorations.Underline))
{
MessageBox.Show("Wow We did it :)");
backgroundUnderline.Stroke = Brushes.Black;
}
}
和XAML代碼:
<Grid x:Name="Center" Margin="10,231,10,10">
<Rectangle Fill="#B2F4F4F5" Stroke="Black" Margin="1,0,-1,0"/>
<Label x:Name="labelNotepad" Content="Notepad" HorizontalAlignment="Left" VerticalAlignment="Top" Width="385" FontWeight="Bold" Background="#FFC1FCFF" FontSize="21.333" Height="56" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="2,1,0,0" BorderThickness="0,0,1,0"/>
<RichTextBox x:Name="richTextBox" Margin="1,58,0,0" FontSize="16" BorderThickness="1,2,1,1" BorderBrush="Black" UseLayoutRounding="False" VerticalScrollBarVisibility="Auto" Background="#7FFFFFFF" SelectionChanged="richTextBox_SelectionChanged">
<FlowDocument/>
</RichTextBox>
的是從你嘗試的結果?異常或空字符串等? – SeeuD1
在messageBox中,我只有一些像TextAligmentPropety這樣的方法,你知道的方法名稱,在另一箇中,我有像「左」,「粗體」等結果。 – Sagev
你可以添加到你的問題和截圖或其他的東西幫助 – SeeuD1