0

我正在开发一个应用程序,它提供富文本编辑功能,具有浅色和深色主题。当切换到深色主题时,我无法查看焦点文本,并且在切换焦点时任何文本颜色都会丢失。我创建了一个简单的文本框,它有两个富文本框,一个将所选文本更改为红色的按钮,以及两个用于在明暗主题之间切换的按钮。我正在对丰富的编辑框应用样式,但看起来忽略了 x:Key="TextControlForegroundFocused",或者可能在应用主题 cahnges 之前计算 SystemBaseHighColor。

XAML

<Page.Resources>

    <!-- RichEditBox Styling-->
    <SolidColorBrush x:Key="TextControlForegroundFocused" Color="{ThemeResource SystemBaseHighColor}"/>
    <SolidColorBrush x:Key="TextControlForegroundDisabled" Color="{ThemeResource SystemBaseHighColor}"/>
    <SolidColorBrush x:Key="TextControlBackgroundFocused" Color="{ThemeResource TextControlForeground}"/>

</Page.Resources>

<StackPanel Name="_Root" >

    <StackPanel Orientation="Horizontal" >
        <Button Content="Red" Click="OnRed"/>
        <Button Content="Dark Theme" Click="OnDark"/>
        <Button Content="Light Theme" Click="OnLight"/>
    </StackPanel>
    <StackPanel Orientation="Horizontal">
        <RichEditBox Name="RichEditor1" Style="{ThemeResource EditBoxStyle}" Width="250" Height="200"/>
        <RichEditBox Name="RichEditor2" Style="{ThemeResource EditBoxStyle}" Width="250" Height="200"/>
    </StackPanel>

</StackPanel>

C#

    private void OnRed(object sender, RoutedEventArgs e)
    {
        RichEditor1.Document.Selection.CharacterFormat.ForegroundColor = Colors.Red;
        RichEditor2.Document.Selection.CharacterFormat.ForegroundColor = Colors.Red;
    }

    private void OnDark(object sender, RoutedEventArgs e)
    {
        _Root.RequestedTheme = ElementTheme.Dark;
        _Root.Background = new SolidColorBrush(Colors.Black);
    }
    private void OnLight(object sender, RoutedEventArgs e)
    {
        _Root.RequestedTheme = ElementTheme.Light;
        _Root.Background = new SolidColorBrush(Colors.White);
    }

关于如何使这项工作的任何建议?

4

0 回答 0