views:

1652

answers:

2

Is it possible to access the following formatted menu item like any other standard menu item (using the underscore-method, e.g. "_File" would be accessible by pressing "f")? I would like to use "O" as "access key" here.

Unfortunately, <AccessText> does not seem to be usable directly (I imaginged something like

<AccessText Visibility="Collapsed">_O2-Genion</AccessText>

in a <StackPanel>, but alas, this did not work out.)

<MenuItem>
  <MenuItem.Header>
    <TextBlock>
      O
      <Span BaselineAlignment="Subscript">
        <TextBlock Margin="-3,0,0,0" FontSize="8">
        2
        </TextBlock>
      </Span>
      -Genion
    </TextBlock>
  </MenuItem.Header>
</MenuItem>

Any suggestions?

A: 

Do you even need to use an AccessKey at all? Assuming that you didn't need/want the custom styling of the MenuItem header text, you could get the same affect by doing the following:

<MenuItem HeaderText="_02" />

Would just putting an underscore before the 0 work? Although I seem to recall that one difference between TextBlock and Label is that TextBlock doesn't support access keys, but Label does. If that's the case, maybe use a Label instead of a TextBlock in your menu item?

Andy
+1  A: 

As I need the subscript, I cannot avoid the custom formatting. What I found out to be an ugly, but obviously possible solution is the following:

<MenuItem>
  <MenuItem.Header>
    <StackPanel Orientation="Horizontal">
      <AccessText>_O</AccessText>
      <TextBlock>
        <Span BaselineAlignment="Subscript" FontSize="8">2</Span>-Genion
      </TextBlock>
    </StackPanel>
  </MenuItem.Header>
</MenuItem>