gpt4 book ai didi

c# - Silverlight 5 双击总是将 ClickCount 返回为 1

转载 作者:太空狗 更新时间:2023-10-29 18:16:39 28 4
gpt4 key购买 nike

我为 DataGrid 创建了检测双击的行为:

public class DataGridDoubleClickBehavior : Behavior<DataGrid>    
{
public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register(
"CommandParameter",
typeof(object),
typeof(DataGridDoubleClickBehavior),
new PropertyMetadata(null));

public object CommandParameter
{
get { return GetValue(CommandParameterProperty); }
set { SetValue(CommandParameterProperty, value); }
}

public static readonly DependencyProperty DoubleClickCommandProperty = DependencyProperty.Register(
"DoubleClickCommand",
typeof(ICommand),
typeof(DataGridDoubleClickBehavior),
new PropertyMetadata(null));

public ICommand DoubleClickCommand
{
get { return (ICommand)GetValue(DoubleClickCommandProperty); }
set { SetValue(DoubleClickCommandProperty, value); }
}

protected override void OnAttached()
{
this.AssociatedObject.LoadingRow += this.OnLoadingRow;
this.AssociatedObject.UnloadingRow += this.OnUnloadingRow;

base.OnAttached();
}

protected override void OnDetaching()
{
this.AssociatedObject.LoadingRow -= this.OnLoadingRow;
this.AssociatedObject.UnloadingRow -= this.OnUnloadingRow;

base.OnDetaching();
}

private void OnLoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.MouseLeftButtonUp += this.OnMouseLeftButtonUp;
}

private void OnUnloadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.MouseLeftButtonUp -= this.OnMouseLeftButtonUp;
}

private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount < 2) return;

if (this.DoubleClickCommand != null) this.DoubleClickCommand.Execute(this.CommandParameter);
}
}

一切似乎都很好,只是它没有记录多次点击。在 OnMouseLeftButtonUp 中,ClickCount 始终为 1。有人知道为什么吗?

最佳答案

我找到了一个非常简单的解决方案。只需替换事件处理程序注册语法

myDataGrid.MouseLeftButtonDown += this.MyDataGrid_MouseLeftButtonDown;

使用 AddHandler 语法

myDataGrid.AddHandler(DataGrid.MouseLeftButtonDownEvent,
new MouseButtonEventHandler(this.MyDataGrid_MouseLeftButtonDown),
handledEventsToo: true)

这样可以指定神奇的 bool 值 handledEventsToo 参数。

这也将处理已处理的事件。

关于c# - Silverlight 5 双击总是将 ClickCount 返回为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9764837/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com