BeginInvoke와 비동기 적으로 DataGrid.UnselectAll을 호출해야 제대로 작동합니다. 나는이 문제를 처리하기 위해 다음과 같은 연결된 속성을 썼다 :
using System;
using System.Windows;
using System.Windows.Threading;
using Microsoft.Windows.Controls;
namespace DataGridNoSelect
{
public static class DataGridAttach
{
public static readonly DependencyProperty IsSelectionEnabledProperty = DependencyProperty.RegisterAttached(
"IsSelectionEnabled", typeof(bool), typeof(DataGridAttach),
new FrameworkPropertyMetadata(true, IsSelectionEnabledChanged));
private static void IsSelectionEnabledChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var grid = (DataGrid) sender;
if ((bool) e.NewValue)
grid.SelectionChanged -= GridSelectionChanged;
else
grid.SelectionChanged += GridSelectionChanged;
}
static void GridSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
var grid = (DataGrid) sender;
grid.Dispatcher.BeginInvoke(
new Action(() =>
{
grid.SelectionChanged -= GridSelectionChanged;
grid.UnselectAll();
grid.SelectionChanged += GridSelectionChanged;
}),
DispatcherPriority.Normal, null);
}
public static void SetIsSelectionEnabled(DataGrid element, bool value)
{
element.SetValue(IsSelectionEnabledProperty, value);
}
public static bool GetIsSelectionEnabled(DataGrid element)
{
return (bool)element.GetValue(IsSelectionEnabledProperty);
}
}
}
내가 내 솔루션을 만드는
this blog post을 공급.
당신이 그것을 읽기 전용으로 만들 하시겠습니까을? – Archie
이미 읽기 전용입니다. 나는 세포의 성질을 통해 그것을 쉽게 할 수 있었다. 난 그냥 행 선택을 허용하고 싶지 않아. 선택한 행을 선택되지 않은 행과 동일한 스타일로 지정하는 것이 대답 일 수 있다고 생각하기 시작했습니다. – Kilhoffer