0

I am trying to underline a label as explained here but it does not work. An error appears saying:

Mode must be specified for RelativeSource

But I have already indicated it:

    <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>

What's wrong here?

Il Vic
  • 5,576
  • 4
  • 26
  • 37
Willy
  • 9,848
  • 22
  • 141
  • 284
  • 1
    That works for me. Try to rebuild all. And why don't you directly use a TextBlock? There seems to be no need for the Label. – Clemens Jun 16 '17 at 09:46

3 Answers3

0

This is an annoying glitch of visual studio. Just rebuild the project.

El Barrent
  • 165
  • 5
0

The code seems to be alright. I used your code in my VS, that message only appeared once, once I clean and rebuilt the code, the error is gone.

Ashu
  • 24
  • 3
0

Just to show how this should actually be done by setting the Label's Template property instead of the Tag property workaround:

<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>
Clemens
  • 123,504
  • 12
  • 155
  • 268