2
我有一個richtextbox綁定到菜單項,以允許粗體,斜體和下劃線以及剪切複製和粘貼。但是,如何將richtextbox內容轉化爲後面的代碼字符串,該代碼將帶有粗體,斜體等?richtextbox到字符串
</DockPanel>
<DockPanel Height="259" VerticalAlignment="Bottom">
<Menu DockPanel.Dock="Top">
<MenuItem Header="Edit">
<MenuItem Command="Cut" Header="_Cut" />
<MenuItem Command="Copy" Header="C_opy" />
<MenuItem Command="Paste" Header="_Paste" />
</MenuItem>
</Menu>
<ToolBarTray DockPanel.Dock="Top">
<ToolBar>
<Button Command="Cut" Content="Cut" />
<Button Command="Copy" Content="Copy" />
<Button Command="Paste" Content="Paste" />
<ToggleButton MinWidth="40"
Command="EditingCommands.ToggleBold"
CommandTarget="{Binding ElementName=XAMLRichBox}"
TextBlock.FontWeight="Bold">B</ToggleButton>
<ToggleButton MinWidth="40"
Command="EditingCommands.ToggleItalic"
CommandTarget="{Binding ElementName=XAMLRichBox}"
TextBlock.FontStyle="Italic">I</ToggleButton>
<ToggleButton MinWidth="40"
Command="EditingCommands.ToggleUnderline"
CommandTarget="{Binding ElementName=XAMLRichBox}">
<TextBlock TextDecorations="Underline">U</TextBlock>
</ToggleButton>
</ToolBar>
</ToolBarTray>
<RichTextBox HorizontalAlignment="Left" Margin="0,0,0,0" Name="richTextBox1" Height="211" VerticalAlignment="Top" Width="398" />
在後面的代碼我試圖做到這一點(不知道如何做到這一點),但正文塊剛出來爲普通文本它不包含大膽等
private void button1_Click(object sender, RoutedEventArgs e)
{
string myText = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text;
textBlock1.Text = myText;
可能的重複http://stackoverflow.com/questions/957441/richtextbox-wpf-does-not-have-string-property-text – 2012-04-20 19:55:18
嘿喬舒亞甚至沒有關閉。 – 2012-04-20 19:55:44
@KristyWhite它在編輯之前。 – 2012-04-20 19:57:47