【问题标题】:XAML Label: binding text content when using text stylesXAML 标签:使用文本样式时绑定文本内容
【发布时间】:2012-01-16 10:01:06
【问题描述】:

我有以下 XAML:

<Label>
    <Underline Foreground="Blue">Foo</Underline>
</Label>

现在我想在运行时使用绑定替换文本“Foo”,但显然我不能在此处放置 {..} 绑定来代替 Foo。这样做的正确方法是什么?

【问题讨论】:

  • Content="{Binding Text} ?(只是猜测)
  • 它通常是'Content="{Binding Text}',这是一个很好的猜测,但是这个控件是不同的。非常出乎意料。

标签: c# xaml data-binding binding


【解决方案1】:

我遇到了这个,

<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

它是这么说的,

一个内联流内容元素,它使内容呈现带有下划线的文本装饰。

所以它是一组内联,并采用this的格式,

<Underline>
  Inlines
</Underline>

【讨论】:

    猜你喜欢
    • 2018-02-14
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多