あなたがこのすべてのコンテキストを秘密にしているので、私は確信が持てませんが、Setter
はTextBlock
に適用されているStyle
です。
その場合、代わりにLabel
(またはContentControl
の子孫)を使用し、そのContentStringFormat
プロパティを設定することもできます。
<Style
x:Key="oneMatchLabelStyle"
TargetType="Label"
BasedOn="{StaticResource {x:Type Label}}"
>
<Setter Property="Content" Value="{DynamicResource oneMatch}" />
<Setter Property="ContentStringFormat" Value="This is {0}" />
<!-- Set padding to 0 so it'll look like TextBlock did in your layout -->
<Setter Property="Padding" Value="0" />
</Style>
...
<Label Style="{DynamicResource oneMatchLabelStyle}" />
あなたは文字列リソース自体に先頭のスペースを追加したい場合は、単にXAMLで改行なしスペース(Unicode U+00A0
)を指定します。 HTML文字エンティティ
はXAMLでサポートされているので、代わりに進文字エンティティを使用していません。
<sys:String x:Key="oneMatch"> Blah blah blah</sys:String>
し、任意の特別なフォーマットせずにそのリソースを使用します。
コンバータの適用はどうですか? http://stackoverflow.com/questions/378979/is-it-possible-to-use-a-converter-within-a-style – zquanghoangz