Wpf 在标签下面划线
我试图在一个标签下面画线,但它不起作用。出现一个错误,说明:Wpf 在标签下面划线,wpf,xaml,visual-studio-2008,label,.net-3.5,Wpf,Xaml,Visual Studio 2008,Label,.net 3.5,我试图在一个标签下面画线,但它不起作用。出现一个错误,说明: 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" Te
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>
这里出了什么问题?这是visual studio的一个恼人的小故障。只要重建这个项目 代码似乎没问题。我在我的VS中使用了您的代码,该消息只出现了一次,一旦我清理并重新生成代码,错误就消失了。只是为了说明如何通过设置标签的
模板
属性而不是标记
属性解决方法来实际执行此操作:
<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>
这对我很有用。试着重建所有。为什么不直接使用文本块呢?似乎没有必要贴标签。