我有一個非常簡單的WPF按鈕,應該調用MouseDown上的函數preview()
,並且函數hide()
上的MouseUp。然而它不起作用,並且甚至沒有擊中其事件處理程序。我的錯誤是什麼?爲什麼MouseDown事件處理程序沒有被擊中?
我試着改變背景屬性,沒用。 MouseLeave and MouseClick這兩個工作,但這不是我想要的。
XAML:
<Button x:Name="previewButton" Background="#FF383434" Margin="5,5,8,0" MouseDown="previewButton_MouseDown" MouseUp="previewButton_MouseUp" MouseLeave="previewButton_MouseLeave" TouchDown="previewButton_TouchDown" TouchUp="previewButton_TouchUp" TouchLeave="previewButton_TouchLeave" Grid.Row="1" Click="previewButton_Click" Padding="0" >
<StackPanel Height="98" Width="49">
<Image Source="/EZ3D;component/Resources/old/eye.png" Margin="0,17,0,0" />
<TextBlock Text="Preview" TextWrapping="WrapWithOverflow" Margin="0" HorizontalAlignment="Center" Padding="0" FontSize="13" VerticalAlignment="Center"/>
</StackPanel>
</Button>
代碼隱藏
private void previewButton_TouchDown(object sender, TouchEventArgs e)
{
ShowPreviewImage();
}
private void previewButton_TouchUp(object sender, TouchEventArgs e)
{
HidePreviewImage();
}
private void previewButton_TouchLeave(object sender, TouchEventArgs e)
{
HidePreviewImage();
}
private void previewButton_MouseDown(object sender, MouseButtonEventArgs e)
{
ShowPreviewImage();
}
private void previewButton_Click(object sender, RoutedEventArgs e)
{
ShowPreviewImage();
}
private void previewButton_MouseUp(object sender, MouseButtonEventArgs e)
{
HidePreviewImage();
}
private void previewButton_MouseLeave(object sender, MouseEventArgs e)
{
HidePreviewImage();
}
您是否碰巧嘗試過PreviewMouseDown事件? – Bobby
@bob不,我沒有。那是什麼? –