【问题标题】:Underline a Label在标签下划线
【发布时间】:2017-11-19 00:51:47
【问题描述】:

我正在尝试按照here 的说明在标签下划线,但它不起作用。出现错误提示:

Mode must be specified for RelativeSource

但是我已经指出了:

    <Label Grid.Row="0" Grid.Column="0" Tag="ID" FontWeight="Bold" Margin="10,5" HorizontalAlignment="Left">
         <TextBlock TextDecorations="Underline" Text="{Binding Path=Tag, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Label}}}"    />
   </Label>

这里有什么问题?

【问题讨论】:

  • 这对我有用。尝试重建所有。为什么不直接使用TextBlock?似乎不需要标签。

标签: wpf xaml visual-studio-2008 label .net-3.5


【解决方案1】:

代码似乎没问题。我在我的VS中使用了你的代码,该消息只出现过一次,一旦我清理并重建代码,错误就消失了。

【讨论】:

    【解决方案2】:

    这是视觉工作室的一个恼人的故障。只需重建项目。

    【讨论】:

      【解决方案3】:

      只是为了说明应该如何通过设置标签的Template 属性而不是Tag 属性解决方法:

      <Label Content="ID" FontWeight="Bold" Margin="10,5" HorizontalAlignment="Left">
          <Label.Template>
              <ControlTemplate TargetType="Label">
                  <TextBlock Margin="{TemplateBinding Padding}"
                             TextDecorations="Underline"
                             Text="{Binding Path=Content,
                                    RelativeSource={RelativeSource AncestorType=Label}}"/>
              </ControlTemplate>
          </Label.Template>
      </Label>
      

      【讨论】:

        猜你喜欢
        • 2017-01-20
        • 2022-11-24
        • 2013-05-26
        • 2014-02-01
        • 2018-08-15
        • 1970-01-01
        • 2014-01-18
        • 1970-01-01
        • 2017-05-31
        相关资源
        最近更新 更多