次のコードを XAML として記述する方法
このコードのスニップがあると仮定します
var myValue = someMethodeReturn(); // the return will fit
// could also be an other nonbindable property
var myTextBlock = new TextBlock();
myTextBlock.Inlines = myValue;
どのように変換しますか
var myValue = someMethodeReturn();
と
myTextBlock.Inlines = myValue;
XAML のみとして
確かに最初の部分は次のように見え、2番目の部分は次のように見える ???={Binding myProperty}
かもしれません<TextBlock.Inlines><???/></TextBlock.Inlines>
が、どのよう???
に見えるでしょうか?
視覚的な結果は次のようになります (ソリューションを実行した場合)
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="LightGray" TextWrapping="WrapWithOverflow" >
<TextBlock.Inlines>
<Run>meine sehr sehr sehr sehr sehr sehr sehr sehr sehr sehr sehr lange run 1</Run>
<Run Foreground="Green" FontFamily='Palatino Linotype' Typography.Variants='Superscript'>meine run2</Run>
<Run>meine sehr sehr sehr sehr sehr sehr sehr sehr sehr sehr sehr lange run</Run>
<Run Foreground="LimeGreen" Background="Yellow">meine run3</Run>
<Run>meine sehr sehr sehr sehr sehr sehr sehr sehr sehr sehr sehr lange run</Run>
</TextBlock.Inlines>
</TextBlock>
ItemsControl
タグ間でテストしましTextBlock.Inlines
たが、デフォルトとして TextBlocks が返され、設定できませんでしたRun
。InLine
ItemTemplate
aControl
を返す aだけが必要だと思いますが、どれがこれを実行できるList<Inline>
かわかりませんControl
任意の提案をいただければ幸いです
私は次の考えを試しました
初め
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="LightGray" TextWrapping="WrapWithOverflow" >
<TextBlock.Inlines>
<ContentControl Content="{Binding myBinding}"/>
</TextBlock.Inlines>
</TextBlock>
"(Auflistung)" をテキストとして返す
セカンド
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="LightGray" TextWrapping="WrapWithOverflow" >
<TextBlock.Inlines>
<ItemsControl ItemsSource="{Binding myBinding}"/>
</TextBlock.Inlines>
</TextBlock>
でラップされた TextBoxes のリストを返しますContenPresenter