/// <summary> /// Handles the mouse left button down event on data selector. /// </summary> /// <param name="sender">Sender of the event.</param> /// <param name="e">Event arguments containing instance data.</param> private void DataSelector_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (!this.IsMouseCaptured) { FrameworkElement element = e.OriginalSource as FrameworkElement; if (element.DataContext != null) { this.mouseCaptured = this.CaptureMouse(); this.oldIndex = this.GetIndex(e.OriginalSource); this.popUp.DataContext = element.DataContext; this.dataSelectorItem = this.GetDataSelectorItem(element); } } }
/// <summary> /// Gets the data selector item corresponding to the element. /// </summary> /// <param name="element">Element to which data selector item needs to be determined.</param> /// <returns>Data selector item corresponding to the element.</returns> private DataSelectorItem GetDataSelectorItem(FrameworkElement element) { DataSelectorItem dataSelectorItem = element as DataSelectorItem; if (dataSelectorItem != null) { return(dataSelectorItem); } else { FrameworkElement parent = element.Parent as FrameworkElement; if (parent != null) { return(this.GetDataSelectorItem(parent)); } } return(null); }
/// <summary> /// Handles the mouse left button up event on data selector. /// </summary> /// <param name="sender">Sender of the event.</param> /// <param name="e">Event arguments containing instance data.</param> private void DataSelector_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (this.IsMouseCaptured && this.dataSelectorItem != null) { DataSelectorItem newDataSelectorItem = null; this.popUp.IsOpen = false; this.ReleaseMouseCapture(); this.mouseCaptured = false; int newIndex = -1; #if SILVERLIGHT if (e.OriginalSource != null) { newIndex = this.GetIndex(e.OriginalSource); newDataSelectorItem = this.GetDataSelectorItem(e.OriginalSource as FrameworkElement); } #else HitTestResult result = VisualTreeHelper.HitTest(this, e.GetPosition(this)); if (result != null) { newIndex = this.GetIndex(result.VisualHit); newDataSelectorItem = this.GetDataSelectorItem(result.VisualHit as FrameworkElement); } #endif if (this.oldIndex > -1 && newIndex > -1 && this.oldIndex != newIndex && newDataSelectorItem != null) { this.Swap(this, new ReorderedEventArgs(this.oldIndex, newIndex)); } if (this.dataSelectorItem != newDataSelectorItem) { this.dataSelectorItem.ClearHoverStyle(); } this.dataSelectorItem = null; this.oldIndex = -1; } }