你需要的地方簡單RoutedEventArgs使用MouseButtonEventArgs:
代碼隱藏:
private void button_WithDoubleClick_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("Double click");
}
private void button_RaiseDoubleClick_Click(object sender, RoutedEventArgs e)
{
var args = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left)
{
RoutedEvent = Control.MouseDoubleClickEvent
};
this.button_WithDoubleClick.RaiseEvent(args);
}
的XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Name="button_WithDoubleClick" Content="Button with double click" MouseDoubleClick="button_WithDoubleClick_MouseDoubleClick" />
<Button Grid.Row="1" Name="button_RaiseDoubleClick" Content="Button to raise double click" Click="button_RaiseDoubleClick_Click"/>
</Grid>
P.S:我不知道什麼應該被指定爲第二個構造函數參數有關的MouseButtonEventArgs
的價值 - The time when the input occurred.
。 0在這個演示中效果很好,但它是否能用於更復雜的交互,我不知道。
你嘗試傳遞'新的MouseButtonEventArgs'而不是'RoutedEventArgs'嗎? – 2015-03-31 09:22:07