2012-02-22 14 views
1

データベースから読み込み中のテキストがあります。このテキストは、xamlセクションオブジェクトの文字列表現です。このテキストは、コンボボックスからの選択に基づいて異なります。ここにいくつかのテキストの例があります:文字列を使用してフロードキュメントを作成する

<Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="LeftToRight" NumberSubstitution.CultureSource="User" NumberSubstitution.Substitution="AsCulture" FontFamily="Verdana" FontStyle="Normal" FontWeight="Normal" FontStretch="Normal" FontSize="11" Foreground="#FF000000" Typography.StandardLigatures="True" Typography.ContextualLigatures="True" Typography.DiscretionaryLigatures="False" Typography.HistoricalLigatures="False" Typography.AnnotationAlternates="0" Typography.ContextualAlternates="True" Typography.HistoricalForms="False" Typography.Kerning="True" Typography.CapitalSpacing="False" Typography.CaseSensitiveForms="False" Typography.StylisticSet1="False" Typography.StylisticSet2="False" Typography.StylisticSet3="False" Typography.StylisticSet4="False" Typography.StylisticSet5="False" Typography.StylisticSet6="False" Typography.StylisticSet7="False" Typography.StylisticSet8="False" Typography.StylisticSet9="False" Typography.StylisticSet10="False" Typography.StylisticSet11="False" Typography.StylisticSet12="False" Typography.StylisticSet13="False" Typography.StylisticSet14="False" Typography.StylisticSet15="False" Typography.StylisticSet16="False" Typography.StylisticSet17="False" Typography.StylisticSet18="False" Typography.StylisticSet19="False" Typography.StylisticSet20="False" Typography.Fraction="Normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.EastAsianExpertForms="False" Typography.Variants="Normal" Typography.Capitals="Normal" Typography.NumeralStyle="Normal" Typography.NumeralAlignment="Normal" Typography.EastAsianWidths="Normal" Typography.EastAsianLanguage="Normal" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.StylisticAlternates="0"><Paragraph><Run>Hello World  </Run></Paragraph></Section> 

このテキストを適切にフォーマットして、アプリケーションのコントロールに表示する必要があります。私はこれを行うために、FlowDocumentViewer(私はFlowDocumentScrollViewerを使用しています)が必要と考えています。

私が理解できないことは、ドキュメントドキュメントビューアに関連付けることができるように、テキストをフロードキュメントにどうやって取得するかです(そして、私はこれについてnoobです)。

誰でも手助けできますか?

答えて

6

XamlReader.Parseを使用して、文書に追加できる文字列からSectionを作成することができます。

+0

これは素晴らしい仕事しました!ありがとう! –

+0

@ TheSheekGeek:それを聞いてうれしい、あなたは大歓迎です:) –

0

は私が完全なコードを追加してみましょう:

public static FlowDocument ToFlowDocument(string xmlString) 
{ 
    var result = new FlowDocument(); 

    if (!string.IsNullOrEmpty(xmlString)) 
    { 
     result.Blocks.Add((Section)XamlReader.Parse(xmlString)); 
    } 

    return result;   
} 
関連する問題