2012-05-10 7 views
3

私のWPFアプリケーションでは、何かがドロップしそうなときはいつでもListViewItemを強調表示する必要があります。私は、スタイルを適用するためにListViewItemのOnDragEnter、OnDragOver、OnDragLeaveなどをオーバーライドします(バックグラウンドの変更など)。それは正常に動作しています。しかし、リストビューの項目に何かをドロップした後、リストビューの項目をクリックすると、選択とマウスオーバーのエフェクトが正常に動作していません。どうすればこの問題を解決できますか?あなたのローカル値のDragDropを行った後WpfハイライトListViewItem On Dragドロップ

public class CustomListViewItem : ListViewItem 
{ 
    protected override void OnDragOver(System.Windows.DragEventArgs e) 
    { 
     this.Background = Brushes.Green; 
     base.OnDragOver(e); 
    } 

    protected override void OnDragEnter(System.Windows.DragEventArgs e) 
    { 
     this.Background = Brushes.Green; 
     base.OnDragEnter(e); 
    } 

    protected override void OnDragLeave(System.Windows.DragEventArgs e) 
    { 
     if (!this.IsSelected) 
     { 
      this.Background = Brushes.Transparent; 
      this.BorderBrush = Brushes.Transparent; 
     } 
     base.OnDragLeave(e); 
    } 
} 

答えて

3

は(Dependency Property Setting Precedence List を参照)スタイルで選択し、マウスオーバー効果よりも優先されます。

DependencyObject.ClearValue Methodを試してみてください。完全に働いた

protected override void OnDragLeave(System.Windows.DragEventArgs e) 
{ 
    if (!this.IsSelected) 
    { 
     this.ClearValue(BackgroundProperty); 
     this.ClearValue(BorderBrushProperty); 
    } 
    base.OnDragLeave(e); 
} 
+0

。 –

関連する問題