Tôi tạo ra hành vi cho DataGrid để phát hiện kích đúp vào:Silverlight 5 nhấp đúp luôn trả ClickCount như 1
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);
}
}
Tất cả mọi thứ có vẻ là tốt ngoại trừ việc nó không ghi lại nhiều lần bấm chuột. Trong OnMouseLeftButtonUp
ClickCount luôn luôn 1. Không ai biết tại sao?
Là một vài kiểm tra tính chính xác, có thể chạy mẫu của Pete để xác thực rằng nó hoạt động và/hoặc chạy một trong các dự án SL4 DataGrid + DoubleClick hiện có như http://www.codeproject.com/Articles/115405/Double-Click -DataGrid-in-Silverlight? –
Những gì tôi đang làm là một phần của bản nâng cấp SL5. Loại bỏ mã như thế vì đa nhấp chuột thực sự "được hỗ trợ" ... Tôi có mã hoạt động. Tôi chỉ muốn làm cho nó đúng. – katit