我有以下XAML:
<Label>
<Underline Foreground="Blue">Foo</Underline>
</Label>
现在我想在运行时使用绑定替换文本“Foo”,但显然我不能在这里放置{..}绑定代替Foo。这样做的正确方法是什么?
答案 0 :(得分:4)
我遇到了这个,
<Label>
<Underline Foreground="Blue">
<Underline.Inlines>
<TextBlock Text="{Binding Text}"></TextBlock>
</Underline.Inlines>
</Underline>
</Label>
事实上你可以减少这个,
<Label>
<Underline Foreground="Blue">
<TextBlock Text="{Binding Text}"></TextBlock>
</Underline>
</Label>
或者你可以这样做,
<Label Name="label">
<TextBlock Name="textBlock" TextDecorations="Underline" Text="Test"/>
</Label>
回到你的下划线,文字'Foo'你定义了一个内联。
http://msdn.microsoft.com/en-us/library/system.windows.documents.underline.aspx
它说,
内联级流内容元素,它使内容呈现带下划线的文本修饰。
所以它是一组内联,并采用这种格式,
<Underline>
Inlines
</Underline>