private void OnPreviewMouseMoveWhileCaptured(object sender, MouseEventArgs e) { if (e.LeftButton != MouseButtonState.Pressed) { if (!((Mouse.Captured is ComboBox && ((ComboBox)Mouse.Captured).IsDropDownOpen))) //Combo boxes require non-pressed capture behaviour while popped up to work properly. { if (Mouse.Captured != null) { Mouse.Captured.ReleaseMouseCapture(); } OnLostMouseCapture(e); } } else { //Shift the mouse with the panel being moved, so that the resize remains relative to it. ArtPanel panel = GetArtPanel(e.OriginalSource); if (panel != null) { panel.BringIntoView(); //Ensure the panel remains in view Point newOffset = panel.TranslatePoint(new Point(), this); Vector offsetDelta = newOffset - mPanelResizeDragOffset; if (offsetDelta.Length > 1) { MoveMousePosition(offsetDelta); mPanelResizeDragOffset = newOffset; e.Handled = true; } } } }
protected override void OnLostMouseCapture(MouseEventArgs e) { base.OnLostMouseCapture(e); PreviewMouseMove -= OnPreviewMouseMoveWhileCaptured; Suspended = false; ArtPanel panel = GetArtPanel(e.OriginalSource); if (panel != null) { if (panel.Parent == null) { //The panel has been removed (probably due to image size changed), so find the new panel for that album art, and bring that into view instead ContentPresenter contentPresenter = ItemContainerGenerator.ContainerFromItem(panel.AlbumArt) as ContentPresenter; if (contentPresenter != null) { contentPresenter.BringIntoView(); } } else { panel.BringIntoView(); //Ensure the panel remains in view } } }
private static object CoerceIsSaved(DependencyObject sender, object value) { ArtPanel artPanel = (ArtPanel)sender; if (artPanel.FilePathEditor != null && artPanel.FilePathTextBox != null && artPanel.FilePathEditor.Visibility == Visibility.Visible && artPanel.FilePathTextBox.Text != artPanel.AlbumArt.FilePath) { return(false); //Always appear unsaved when editing } return(value); }
private static object CoerceThumbSize(DependencyObject sender, object value) { ArtPanel artPanel = (ArtPanel)sender; if (artPanel.InformationLocation == InformationLocation.Bottom && artPanel.ActualHeight > 0) { //Take up the full width available //(This has to match the Grid MinWidth calculation) return(artPanel.ActualWidth - artPanel.PanelResizer.ActualWidth - 10); } return(value); }
private static void OnInformationLocationChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { ArtPanel artPanel = (ArtPanel)sender; artPanel.CoerceValue(ThumbSizeProperty); if ((InformationLocation)e.NewValue == InformationLocation.Right) { //If switching to Right, and the Information panel has disappeared, make sure it is at least visible if (artPanel.Width - artPanel.ThumbSize < 30) { artPanel.Width = artPanel.ThumbSize + artPanel.mMinimumGridSizeForLabelColumn + 10; } } }
protected override void OnGotMouseCapture(MouseEventArgs e) { base.OnGotMouseCapture(e); Suspended = true; ArtPanel panel = GetArtPanel(e.OriginalSource); if (panel != null) { mPanelResizeDragOffset = panel.TranslatePoint(new Point(), this); PreviewMouseMove += OnPreviewMouseMoveWhileCaptured; } }
private double GetNearestArrangedPanelWidth(double panelWidth) { int numberOfPanels = (int)Math.Round(ItemsPresenter.ActualWidth / panelWidth, MidpointRounding.AwayFromZero); double newPanelWidth = ItemsPresenter.ActualWidth / numberOfPanels; ContentPresenter firstItemContentPresenter = (ContentPresenter)ItemContainerGenerator.ContainerFromIndex(0); if (firstItemContentPresenter != null) //Will be null if there are no items shown. { ArtPanel firstArtPanel = GetArtPanelFromContentPresenter(firstItemContentPresenter); if (numberOfPanels > 1 && newPanelWidth < firstArtPanel.MinWidth) { //Can't fit the panels at this size, as it is under the minimum size, so decrease the number of panels by one, and recalc. newPanelWidth = ItemsPresenter.ActualWidth / --numberOfPanels; //Should always now fit, as this is the equivalent of rounding up instead of down. } } return(newPanelWidth); }