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 ?

C Sharp, Windows Presentation Foundation
.NET MAUI BilderProblem?

Hallo,

Ich arbeite gerade das erste Mal mit .NET MAUI-App. Ich entwickle gerade eine Statistik App.

Nur irgendwie habe ich Probleme Bilder auf die Oberfläche zu bekommen. Es wird zumindest keins angezeigt.

die Bilder sind im Ordner Resources -> Unterordner Images

C:\Users\klase\source\repos\InusMobil\InusMobil\Resources\Images\

MainPage.xaml (wo die Bilder eingefügt werden)

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="InusMobil.MainPage"
             BackgroundColor="#6B8E23"
             Title="Login">


    <VerticalStackLayout Padding="20" Spacing="20" HorizontalOptions="Center" VerticalOptions="Center">


        <!-- Logo oben zentriert -->
        <Image Source="Resources/Images/inus.png" Aspect="AspectFit" HeightRequest="100" HorizontalOptions="Center" />


        <!-- Login Form -->
        <VerticalStackLayout Padding="10" Spacing="10" HorizontalOptions="Center" VerticalOptions="Center">


            <Image Source="Resources/Images/coins.png" HeightRequest="50" HorizontalOptions="End" />


            <Label Text="Login" FontSize="30" FontAttributes="Bold" HorizontalOptions="Center" TextColor="#FFFFFF"/>


            <HorizontalStackLayout Spacing="10">
                <Image Source="Resources/Images/customeres.png" WidthRequest="30" HeightRequest="30"/>
                <Entry x:Name="UsernameEntry" Placeholder="Benutzername" WidthRequest="250" BackgroundColor="#FFFFFF"/>
            </HorizontalStackLayout>


            <HorizontalStackLayout Spacing="10">
                <Image Source="Resources/Images/secureses.png" WidthRequest="30" HeightRequest="30"/>
                <Entry x:Name="PasswordEntry" Placeholder="Passwort" IsPassword="True" WidthRequest="250" BackgroundColor="#FFFFFF"/>
            </HorizontalStackLayout>


            <HorizontalStackLayout Spacing="10">
                <CheckBox x:Name="ShowPasswordCheckBox"/>
                <Label Text="Passwort anzeigen" VerticalOptions="Center"/>
            </HorizontalStackLayout>


            <Label x:Name="ForgotPasswordLabel" Text="Passwort vergessen" TextColor="#FFFFFF" HorizontalOptions="Center"/>
            <Button Text="Anmelden" Clicked="OnLoginClicked" BackgroundColor="#4CAF50" TextColor="#FFFFFF"/>
        </VerticalStackLayout>
    </VerticalStackLayout>
</ContentPage>

erkennt einer den Fehler ?

ich arbeite wie gesagt dass erste Mal damit. Ansonsten immer mit WinForms, WPF,...

Danke schonmal

App, Android App, C Sharp, Code