How to give an Access key to a button with image on it.? If we press ALT +S then not able fire the click event
<Button Margin="0,0,5,0" Cursor="Hand"
ToolTip="Search" Command="{Binding SearchButton}"
IsEnabled="{Binding ElementName=SaveButton,Path=IsEnabled,
UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click" >
<cmd:EventToCommand
PassEventArgsToCommand="False"
Command="{Binding SearchButton}"
/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Button.ContentTemplate>
<DataTemplate开发者_开发技巧>
<Grid>
<Label Visibility="Collapsed">_Search</Label>
<Image Source="/CHKRevAcc;component/Images/search.png" />
</Grid>
</DataTemplate>
</Button.ContentTemplate>
</Button>
You can use the AccessText element to wrap the text that should have the access key specified.
<Button Margin="0,0,5,0" Cursor="Hand"
ToolTip="Search" Command="{Binding SearchButton}"
IsEnabled="{Binding ElementName=SaveButton,Path=IsEnabled,
UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click" >
<cmd:EventToCommand
PassEventArgsToCommand="False"
Command="{Binding SearchButton}"
/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Button.ContentTemplate>
<DataTemplate>
<Grid>
<AccessText Visibility="Collapsed">_Search</AccessText>
<Image Source="/CHKRevAcc;component/Images/search.png" />
</Grid>
</DataTemplate>
</Button.ContentTemplate>
</Button>
If that doesn't work, then you may not want to set the visibility to collapsed. Instead, make it opaque and shorten the text to
<AccessText Opacity="0">_S</AccessText>
This way, the button will still process the text, but it will be invisible. Not sure if you'll need to take this last step though.
精彩评论