我有一个WPF窗口,其中包含3个带图像和TextBlock的按钮,如下所示:
<Button x:Name="cmdPrint" Margin="5" VerticalAlignment="Center" Grid.Column="2"
ToolTip="Print a simulation"
MouseMove="MouseMouveHandler"
Click="ButtonClickHandler" Height="36">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="70"/>
</Grid.ColumnDefinitions>
<Image Source="images\print.png" Grid.Column="0" VerticalAlignment="Center"
Margin="2"/>
<TextBlock Text="_Print" Grid.Column="1" Foreground="DarkBlue"
VerticalAlignment="Center" Margin="2"/>
</Grid>
</Button>
如您所见,该按钮是自定义的,因此,以下代码不起作用:
<Button Name="cmdPrint " Content="_Print"></Button>
按“P”键时是否可以使用“打印”按钮?
提前谢谢。
答案 0 :(得分:0)
使用标签代替文本块对您有用
Click="ButtonClickHandler" Height="36" > <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="30"/> <ColumnDefinition Width="70"/> </Grid.ColumnDefinitions> <Image Grid.Column="0" VerticalAlignment="Center" Margin="2"/> <Label Content="_Print" Grid.Column="1" Foreground="DarkBlue" VerticalAlignment="Center" Margin="2" /> </Grid> </Button>