
1. Set the accessible name for an element from the accessible name of another element
Sometimes you want the accessible name of an element to always be the same as the accessible name of some other element. For example, the accessible name of a Slider bar might always want to be the accessible name of some nearby TextBlock. (By default the accessible name of a TextBlock is the same as the text shown visually on the TextBlock.) In that case, you can say that the Slider is labeled by the TextBlock.
In the following example, a Sliders accessible name is set from a TextBlock that lies near the Slider visually:
<Slider …
AutomationProperties.LabeledBy={Binding ElementName=CheeseAllowance}/>
<TextBlock …
Name=CheeseAllowance
x:Uid=CheeseAllowanceLabel />
Note that the LabeledBy binding only requires a Name rather than an x:Name.
I can then use Inspect to verify that the accessible name of the Slider has been set from the accessible name of the TextBlock.
Figure 1: Inspect showing the accessible names of my Slider and TextBlock.
Note: It is not possible to set a LabeledBy property in a style such that it is bound to an element in a custom control’s styles ControlTemplate, in the manner attempted below.
<Style TargetType=customControls:CheeseButton>
…
<Setter Property=AutomationProperties.LabeledBy
Value={Binding ElementName=PlaceholderText} /> <- THIS BINDING WILL NOT WORK!
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-49289-1.html
10月16日一定去看
论文就有立足之地
给予颜色