1

Infragistics XamDataCards WPF コントロールでマウスの右ボタンをクリックしてカードを選択する方法は? XamDataCards.ActiveDataItem プロパティも変更する必要があります。

4

2 に答える 2

1

私はすでに解決策を持っています:

/// <summary>
/// selects XamDataCards'es card on right button mouse down even
/// </summary>
public class XamDataCardsSelectCardOnRightMouseClickBehavior : Behavior<XamDataCards>
{
    protected override void OnAttached()
    {
        AssociatedObject.PreviewMouseRightButtonDown += AssociatedObjectPreviewMouseRightButtonDown;
    }

    /// <summary>
    /// select a card on right-click so that a context menu can be displayed
    /// </summary>
    /// <param name="sender">not used</param>
    /// <param name="e">contians mouse position</param>
    private void AssociatedObjectPreviewMouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        VisualTreeHelper.HitTest(this.AssociatedObject, t => HitTestFilterBehavior.Continue, HitTestResultFunc, new PointHitTestParameters(e.GetPosition((UIElement)sender)));
    }

    /// <summary>
    /// WPF invokes this method to report hit test intersections to the user.
    /// If a card was hit, it is set as active (or selected) card.
    /// </summary>
    /// <param name="result">Contains the visual object that was hit.</param>
    /// <returns>Always returns Continue.</returns>
    public HitTestResultBehavior HitTestResultFunc(HitTestResult result)
    {
        DependencyObject dobj = result.VisualHit;
        if (VisualTreeHelper.GetParent(dobj).GetType() == typeof(Infragistics.Windows.DataPresenter.DataRecordPresenter))
        {
            DataRecordPresenter rp = (DataRecordPresenter) VisualTreeHelper.GetParent(dobj);
            this.AssociatedObject.ActiveDataItem = rp.DataRecord.DataItem;
        }
        return HitTestResultBehavior.Continue;
    }
}

そして、それを XamDataCards コントロールに添付するだけです。

于 2012-09-13T12:54:23.593 に答える
1

このソリューションは、カードのヘッダーが右クリックされた場合にもカードを有効にします。

class XamDataCardsActivateOnRightMouseClickBehavior : Behavior<XamDataCards>
{
    protected override void OnAttached()
    {
        AssociatedObject.PreviewMouseRightButtonDown += AssociatedObjectPreviewMouseRightButtonDown;
    }

    private void AssociatedObjectPreviewMouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        CardViewCard card = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(CardViewCard), false) as CardViewCard;
        if (card != null)
        {
            DataRecord record = card.DataContext as DataRecord;
            if (record != null)
            {
                record.DataPresenter.ActiveRecord = record;
            }
        }
    }
}
于 2012-09-13T14:28:36.110 に答える