RichEditBox
で作業していますが、Rtfテキストの保存と復元に問題があります。あなたは正しく(私は読みやすくするために、それを手動でインデントしました)保存異なる前景の色とフォントファミリがある見ることができるようにここでRTFテキストの設定時にRichEditBox(UWP)がフォントとフォアグラウンドを無視します
は、私が書き出したサンプルのRTF形式のテキストです:
{\rtf1\fbidis\ansi\ansicpg1252\deff0\nouicompat\deflang1040
{\fonttbl{\f0\fnil\fcharset0 Segoe UI;}
{\f1\fnil\fcharset0 Brush Script MT;}
{\f2\fnil\fcharset0 Impact;}
{\f3\fnil Segoe UI;}}
{\colortbl ;\red9\green105\blue192;\red0\green0\blue0;\red76\green152\blue25;\red208\green52\blue56;}
{\*\generator Riched20 10.0.14393}\viewkind4\uc1
\pard\ltrpar\tx720\cf1\b\i\f0\fs23 Test\cf2\b0\i0\par
\pard\ltrpar\li320\qc\tx720\cf3\strike\f1\fs40 Some color\cf2\strike0\f0\fs23\par
\pard\ltrpar\tx720\cf4\f2 Hello!\cf2\f0\par
\f3\par
\f0\lang1033\par
\f3\par
\par
\pard\ltrpar\tx720\fs23\par
}
問題:私は
EditBox.Document.SetText(TextSetOptions.FormatRtf, myRtfString);
呼び出し、テキストがコントロールにロードされているが、フォントファミリと前景の色があるコムはっきりと無視された。 は、私はすでに呼び出して試してみた:
EditBox.Document.ApplyDisplayUpdates();
それは問題を解決していません。つまり、他のすべての段落/文字オプションが正しく復元されるのはなぜですか?フォントファミリと前景色だけが無視されます?私はここに何かを逃していますか ありがとう!
編集:
<Style TargetType="RichEditBox" x:Key="CustomRtfEditBoxStyle">
<Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
<Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" />
<Setter Property="Foreground" Value="{ThemeResource TextControlForeground}" />
<Setter Property="Background" Value="{ThemeResource TextControlBackground}" />
<Setter Property="SelectionHighlightColor" Value="{ThemeResource TextControlSelectionHighlightColor}" />
<Setter Property="BorderBrush" Value="{ThemeResource TextControlBorderBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RichEditBox">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Disabled" />
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver" />
<VisualState x:Name="Focused" />
<VisualState x:Name="UnFocused" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border x:Name="BorderElement"
Grid.Row="1"
Background="{ThemeResource TextControlBackgroundFocused}"
BorderThickness="0"
Grid.ColumnSpan="2"
Grid.RowSpan="1" />
<ContentPresenter x:Name="HeaderContentPresenter"
x:DeferLoadStrategy="Lazy"
Visibility="Collapsed"
Grid.Row="0"
Margin="0,0,0,8"
Grid.ColumnSpan="2"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
FontWeight="Normal" />
<ScrollViewer x:Name="ContentElement"
RequestedTheme="Light"
Grid.Row="1"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
IsTabStop="False"
ZoomMode="Disabled"
AutomationProperties.AccessibilityView="Raw" />
<ContentControl x:Name="PlaceholderTextContentPresenter"
Grid.Row="1"
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
IsTabStop="False"
Grid.ColumnSpan="2"
Content="{TemplateBinding PlaceholderText}"
IsHitTestVisible="False" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
は、あなたの答えをありがとうございました!私はすでにこれらのビジュアル状態を取り除いていました(私が使用している完全なスタイルで私の答えを編集しました)、あなたは提案したようにSetText呼び出しをLoadedイベントハンドラに移しました(私はページコンストラクタで呼び出していました)。問題。乾杯! – Sergio0694