2017-06-16 35 views
0

我試圖強調一個標籤,如解釋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> 

有什麼不對嗎?

+1

這對我的作品。嘗試重建所有。爲什麼不直接使用TextBlock?似乎不需要標籤。 – Clemens

回答

0

代碼似乎沒問題。我在我的VS中使用了你的代碼,那個消息只出現過一次,一旦我清理並重建代碼,錯誤消失了。

0

這是一個令人討厭的視覺工作室故障。只需重建該項目。

0

只是爲了展示如何這個實際上應該通過設置標籤的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>