55
A
回答
76
如果您使用TextBlock作爲標籤的內容,其文本將不會吸收下劃線。
26
您可以覆蓋默認模板中標籤的ContentPresenter的RecognizesAccessKey屬性。例如:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.Resources>
<Style x:Key="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}" TargetType="Label">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Label">
<Border>
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
RecognizesAccessKey="False" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Label>_This is a test</Label>
</Grid>
</Page>
+0
剛試過這個,實際上並不起作用。也許它會刪除訪問鍵綁定,但它不會阻止刪除下劃線。 – xanadont 2009-05-14 04:23:47
1
使用<"Text Block">"<"/Text Block">
而不是<"label"><"/label">
來打印具有下劃線的確切文本。
0
爲什麼不能這樣?
public partial class LabelEx : Label
{
public bool PreventAccessKey { get; set; } = true;
public LabelEx()
{
InitializeComponent();
}
public new object Content
{
get
{
var content = base.Content;
if (content == null || !(content is string))
return content;
return PreventAccessKey ?
(content as string).Replace("__", "_") : content;
}
set
{
if (value == null || !(value is string))
{
base.Content = value;
return;
}
base.Content = PreventAccessKey ?
(value as string).Replace("_", "__") : value;
}
}
}
相關問題
- 1. Android - 超鏈接缺少下劃線
- 2. 禁用錨標記並刪除下劃線中的下劃線
- 3. 爲多個WPF文本塊文本加下劃線
- 4. 刪除下劃線中的文本內的下劃線<a>標籤
- 5. WPF富文本框下劃線
- 6. 缺少「筆記本」標籤
- 7. 文本下劃線顯示下劃線
- 8. wysihtml5 - 如何禁用下劃線標記
- 9. 缺少標籤
- 10. 添加下劃線到<img>標籤<a>標籤
- 11. H2標籤用粗體和細線加下劃線
- 12. ID標籤用紅色下劃線
- 13. 虛線下劃線文本
- 14. Xamarin形式WinPhone - 如何使標籤文本下劃線WinPhone?
- 15. 在DataTemplate中的標籤下劃線文本
- 16. 加下劃線或不加下劃線
- 17. 標+下劃線內嵌在WPF
- 18. 給特定文本加下劃線 - FPDF
- 19. 使用下劃線填充數組中缺少的對象
- 20. 刪除PhpStorm藍色標籤下劃線
- 21. ViewPagerIndicator不顯示下劃線標籤
- 22. react-bootstrap標籤有下劃線
- 23. 文本下劃線邊距
- 24. 下劃線的UILabel文本
- 25. uitextview內下劃線文本
- 26. 下劃線編輯文本
- 27. 添加賽格時缺少標籤欄
- 28. 加下劃線的文字
- 29. 休息和標籤 「標籤MyLabel缺少」
- 30. 如何在HTML文本下添加虛線下劃線
是否有你想使用標籤而不是TextBlock的原因? – 2008-09-02 21:36:34
是的 - `Label`處理加速器的功能遠不止於此。也適用於不能被「TextBlock」替代的其他控件(例如`GroupBox`)。 – GraemeF 2010-03-01 10:08:25
這對這個主題很有幫助: http://stackoverflow.com/questions/10452462/make-a-hotkey-to-focus-a-textbox-in-wpf – 2016-01-21 07:52:58