WPF RichTextBox: Schriftart und Schriftgröße ändern sich nicht?
Hallo zusammen, ich habe aktuell ein Problem mit meiner WPF-Anwendung. In meiner Benutzeroberfläche möchte ich die Schriftart und die Schriftgröße des Textes in einer RichTextBox (DescriptionTextBox) ändern. Dafür habe ich zwei ComboBox-Steuerelemente erstellt: eines für die Schriftart und eines für die Schriftgröße. Obwohl die Ereignis-Handler korrekt aufgerufen werden, ändert sich die Darstellung des Textes nicht. Hier ist der relevante Code: XAML <ComboBox Width="100" Margin="5" SelectionChanged="FontFamily_SelectionChanged" Style="{StaticResource RoundedComboBox}"> <ComboBoxItem Content="Arial" IsSelected="True"/> <ComboBoxItem Content="Times New Roman"/> <ComboBoxItem Content="Verdana"/> <ComboBoxItem Content="Helvetica"/> <ComboBoxItem Content="Calibri"/> </ComboBox> <ComboBox Width="100" Margin="5" SelectionChanged="FontSize_SelectionChanged" Style="{StaticResource RoundedComboBox}"> <ComboBoxItem Content="8"/> <ComboBoxItem Content="9"/> <ComboBoxItem Content="10"/> <ComboBoxItem Content="11"/> <ComboBoxItem Content="12"/> <ComboBoxItem Content="14"/> <ComboBoxItem Content="16"/> <ComboBoxItem Content="18"/> <ComboBoxItem Content="20" IsSelected="True"/> <ComboBoxItem Content="22"/> <ComboBoxItem Content="24"/> <ComboBoxItem Content="26"/> <ComboBoxItem Content="28"/> <ComboBoxItem Content="36"/> <ComboBoxItem Content="48"/> <ComboBoxItem Content="72"/> </ComboBox> C# Code private void FontFamily_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox comboBox = sender as ComboBox; if (comboBox.SelectedItem is ComboBoxItem selectedItem && DescriptionTextBox != null) { ApplyPropertyValueToSelection(TextElement.FontFamilyProperty, new FontFamily(selectedItem.Content.ToString())); } } private void FontSize_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox comboBox = sender as ComboBox; if (comboBox.SelectedItem is ComboBoxItem selectedItem) { if (double.TryParse(selectedItem.Content.ToString(), out double fontSize) && DescriptionTextBox != null) { ApplyPropertyValueToSelection(TextElement.FontSizeProperty, fontSize); } } } private void ApplyPropertyValueToSelection(DependencyProperty property, object value) { if (DescriptionTextBox != null) { TextRange selectionRange = new TextRange(DescriptionTextBox.Selection.Start, DescriptionTextBox.Selection.End); selectionRange.ApplyPropertyValue(property, value); } } Problem Wenn ich die Schriftart oder die Schriftgröße in der ComboBox auswähle, wird der entsprechende Event-Handler (FontFamily_SelectionChanged oder FontSize_SelectionChanged) aufgerufen, aber die Darstellung des Textes in der RichTextBox ändert sich nicht. Hat jemand eine Idee ?