<ToolBarTray VerticalAlignment="Top" >
<ToolBar >
<Button Width="20" Content="B" Click="Button_Click"></Button>
<Button Width="20" Content="I" Click="Button_Click_1"></Button>
<Button Width="20" Click="Button_Click_2" >
<TextBlock Text="U" TextDecorations="Underline" ></TextBlock>
</Button>
</ToolBar>
<ToolBar Margin="0,0,-103,0" >
<ComboBox Width="87" SelectionChanged="ComboBox_SelectionChanged" Margin="0" IsEditable="True">
<ComboBoxItem Content="8"></ComboBoxItem>
<ComboBoxItem Content="10"></ComboBoxItem>
<ComboBoxItem Content="12"></ComboBoxItem>
<ComboBoxItem Content="24"></ComboBoxItem>
<ComboBoxItem Content="36"></ComboBoxItem>
</ComboBox>
</ToolBar>
</ToolBarTray>
<TextBox x:Name="text" HorizontalAlignment="Left" Height="110" Margin="10,32,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="445"/>
combobox 设置 IsEditable =true 可以进行编辑哟~
private void Button_Click(object sender, RoutedEventArgs e)
{
text.FontWeight = text.FontWeight == FontWeights.Bold ? FontWeights.Normal : FontWeights.Bold;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
text.FontStyle = text.FontStyle == FontStyles.Italic ? FontStyles.Normal : FontStyles.Italic;
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
text.TextDecorations = text.TextDecorations==TextDecorations.Underline? null:TextDecorations.Underline;
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (text == null) return;
ComboBox com = sender as ComboBox;
if (com == null) return;
ComboBoxItem bi = com.SelectedItem as ComboBoxItem;
if (bi == null) return;
text.FontSize = Convert.ToInt32(bi.Content.ToString());
}