XAML
<Window x:Class="SimpleApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <DockPanel> <ToolBar DockPanel.Dock="Top" Height="26" Name="toolBar1" Width="276"> <Button Margin="0,0,0,-0.2" VerticalAlignment="Top" Click="Button_Click_1">Bold
</Button> <Button Click="Button_Click_2">Italic</Button> <Slider Name="Slider1" Minimum="2" Maximum="72" Width="100"
ValueChanged="Slider1_ValueChanged"/> </ToolBar> <Grid Name="grid1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"/> <ColumnDefinition Width="5"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <ListBox Grid.Column="0" Name="listBox1"
SelectionChanged="listBox1_SelectionChanged"></ListBox> <GridSplitter Name="gridSplitter1" Margin="0" Width="5" Grid.Column="1" HorizontalAlignment="Left"/> <RichTextBox Grid.Column="2" Name="richTextBox1"/> </Grid> </DockPanel> </Window>
Event handling codes
using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace SimpleApp { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); foreach (FontFamily F in Fonts.SystemFontFamilies) { ListBoxItem l = new ListBoxItem(); l.Content = F.ToString(); l.FontFamily = F; listBox1.Items.Add(l); } } private void Button_Click_1(object sender, RoutedEventArgs e) { richTextBox1.Selection.ApplyPropertyValue( FontWeightProperty, FontWeights.Bold); } private void Button_Click_2(object sender, RoutedEventArgs e) { richTextBox1.Selection.ApplyPropertyValue( FontStyleProperty, FontStyles.Italic); } private void Slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double>) { try { richTextBox1.Selection.ApplyPropertyValue(FontSizeProperty, Slider1.Value.ToString()); } catch { } } private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { richTextBox1.Selection.ApplyPropertyValue( FontFamilyProperty, ((ListBoxItem)listBox1.SelectedItem).FontFamily); } } }
No comments:
Post a Comment