我有一个 WPF 难题。我希望一些文本看起来像这样:
Enter this preparer's info: [ComboBox]
Alt+E 是聚焦 ComboBox 的访问键,按下 Alt 时,文本中的 E 应该带有下划线。
我可以获得轻松工作的访问 key :
<Label Target="{Binding ElementName=PreparerComboBox}">
_Enter this preparer's info:</Label>
但是“准备者的”不能是粗体,因为标签不支持运行(据我所知)。
我可以在 TextBlock 中轻松加粗:
<TextBlock>Enter this <Bold>preparer's</Bold> info:</TextBlock>
但是没有定义访问键,所以我尝试在 TextBlock 中添加 AccessText:
<Label Target="{Binding ElementName=PreparerComboBox}">
<TextBlock>
<AccessText>_Enter</AccessText> this <Bold>preparer's</Bold> info:
</TextBlock>
</Label>
但是 AccessText 无法与 TextBlock 中的其余文本正确对齐,并且 Margin 似乎对其没有任何影响。
示例:
到目前为止我想到的最好的就是这个怪物:
<Label Target="{Binding ElementName=PreparerComboBox}">
<WrapPanel>
<AccessText>_E</AccessText>
<TextBlock>nter this <Bold>preparer's</Bold> info:</TextBlock>
</WrapPanel>
</Label>
我在这里缺少什么?看来必须有一种更简单的方法。
最佳答案
变化不大,但怎么样
<Label Target="{Binding ElementName=PreparerComboBox}">
<StackPanel Orientation="Horizontal">
<AccessText>_Enter</AccessText>
<TextBlock xml:space="preserve"> this <Bold>preparer's</Bold> info:</TextBlock>
</StackPanel>
</Label>
关于wpf - 如何将粗体文本和 AccessText 添加到标签或 TextBlock?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4000691/