Exemplo n.º 1
0
        private void GetOwnerAndGenerator()
        {
            itemsOwner = ItemsControl.GetItemsOwner(this);
            if (itemsOwner == null)
            {
                throw new InvalidOperationException("无法从 VirtualizingPanel 找到父 ItemsControl.");
            }

            if (!(itemsOwner is ListViewBase))
            {
                throw new InvalidOperationException("VirtualizingPanel 应该在 ListView.ItemsPanel 中被调用");
            }

            scrollOwner = VisualTreeExtension.GetParentObject <ScrollViewer>(itemsOwner, "PageScrollViewer");
            if (scrollOwner == null)
            {
                throw new InvalidOperationException("无法从父 ItemsControl 找到 ScrollView");
            }

            itemContainerGenerator = itemsOwner.ItemContainerGenerator;
            if (itemContainerGenerator == null)
            {
                throw new InvalidOperationException("无法获取 VirtualizingPanel 所属 ItemsControl 的 ItemContainerGenerator");
            }

            if (!isGeneratorHooked)
            {
                isGeneratorHooked                    = true;
                scrollOwner.ViewChanging            -= ScrollOwnerViewChanging;
                scrollOwner.ViewChanging            += ScrollOwnerViewChanging;
                itemContainerGenerator.ItemsChanged -= ItemContainerGeneratorItemsChanged;
                itemContainerGenerator.ItemsChanged += ItemContainerGeneratorItemsChanged;
            }
        }
Exemplo n.º 2
0
        protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
        {
            var window = VisualTreeExtension.FindMdiWindow(this);

            if (window != null && window.Container != null)
            {
                switch (window.WindowState)
                {
                case WindowState.Maximized:
                    window.Normalize();
                    break;

                case WindowState.Normal:
                    window.Maximize();
                    break;

                case WindowState.Minimized:
                    window.Normalize();
                    break;

                default:
                    throw new InvalidOperationException("Unsupported WindowsState mode");
                }
            }

            e.Handled = true;
        }
Exemplo n.º 3
0
        private void OnMoveThumbDragDelta(object sender, DragDeltaEventArgs e)
        {
            var window = VisualTreeExtension.FindMdiWindow(this);

            if (window != null)
            {
                if (window.WindowState == WindowState.Maximized)
                {
                    window.Normalize();
                }

                if (window.WindowState != WindowState.Minimized)
                {
                    window.LastLeft = Canvas.GetLeft(window);
                    window.LastTop  = Canvas.GetTop(window);


                    var candidateLeft = window.LastLeft + e.HorizontalChange;
                    var candidateTop  = window.LastTop + e.VerticalChange;

                    Canvas.SetLeft(window, Math.Min(Math.Max(0, candidateLeft), window.Container.ActualWidth - 25));
                    Canvas.SetTop(window, Math.Min(Math.Max(0, candidateTop), window.Container.ActualHeight - 25));
                }
            }
        }
Exemplo n.º 4
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            var window = VisualTreeExtension.FindMdiWindow(this);

            if (window != null)
            {
                window.DoFocus(e);
            }

            base.OnMouseDown(e);
        }
Exemplo n.º 5
0
        private void OnResizing(object sender, DragDeltaEventArgs e)
        {
            var window = VisualTreeExtension.FindMDIWindow(this);

            if (window != null)
            {
                if (window.IsFocused == false)
                {
                    window.Focus();
                }

                window.Height = window.ActualHeight;
                window.Width  = window.ActualWidth;

                switch (this.VerticalAlignment)
                {
                case VerticalAlignment.Bottom:
                    var deltaVertical = Math.Min(-e.VerticalChange, window.ActualHeight - window.MinHeight);
                    window.Height -= deltaVertical;
                    break;

                case VerticalAlignment.Top:
                    deltaVertical = Math.Min(e.VerticalChange, window.ActualHeight - window.MinHeight);
                    Canvas.SetTop(window, Canvas.GetTop(window) + deltaVertical);
                    window.Height -= deltaVertical;
                    break;

                default:
                    break;
                }

                switch (this.HorizontalAlignment)
                {
                case HorizontalAlignment.Left:
                    var deltaHorizontal = Math.Min(e.HorizontalChange, window.ActualWidth - window.MinWidth);
                    Canvas.SetLeft(window, Canvas.GetLeft(window) + deltaHorizontal);
                    window.Width -= deltaHorizontal;
                    break;

                case HorizontalAlignment.Right:
                    deltaHorizontal = Math.Min(-e.HorizontalChange, window.ActualWidth - window.MinWidth);
                    window.Width   -= deltaHorizontal;
                    break;

                default:
                    break;
                }
            }

            e.Handled = true;
        }
Exemplo n.º 6
0
        protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
        {
            base.OnLostKeyboardFocus(e);
            FrameworkElement parent = VisualTreeExtension.FindMdiWindow(e.NewFocus as FrameworkElement);

            if ((e.NewFocus is MdiWindow && !Equals(e.NewFocus, this)) || (parent != null && !Equals(parent, this)))
            {
                IsSelected = false;
                Panel.SetZIndex(this, 0);
                var newWindow = (e.NewFocus is MdiWindow) ? (e.NewFocus as MdiWindow) : (parent as MdiWindow);
                Container.SetValue(MdiContainer.SelectedItemProperty, newWindow.DataContext);
                newWindow.IsSelected = true;
            }
        }
Exemplo n.º 7
0
        private void OnMoveThumbDragDelta(object sender, DragDeltaEventArgs e)
        {
            var window = VisualTreeExtension.FindMdiWindow(this);

            if (window != null)
            {
                if (window.WindowState == WindowState.Maximized)
                {
                    return;
                }

                Canvas.SetLeft(window, Math.Max(0, Canvas.GetLeft(window) + e.HorizontalChange));
                Canvas.SetTop(window, Math.Max(0, Canvas.GetTop(window) + e.VerticalChange));

                window.Container.InvalidateSize();
            }
        }
Exemplo n.º 8
0
        private void MenuListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            var    item   = e.ClickedItem as FrameworkElement;
            var    parent = VisualTreeExtension.GetParentObject <ListViewItem>(item, "");
            string tag    = parent.Tag.ToString();

            switch (tag)
            {
            case "Message":
                App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Account.MessagePage));
                break;

            case "VideoDynamic":
                App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Video.DynamicPage));
                break;

            case "MyAnime":
                App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Account.FavoriteAnimePage), "anime");
                break;

            case "MyMovie":
                App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Account.FavoriteAnimePage), "cinema");
                break;

            case "MyFavorite":
                App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Account.FavoriteContainerPage), "Favorite");
                break;

            case "MyCollect":
                App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Account.FavoriteContainerPage), "Collect");
                break;

            case "ViewLater":
                App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Video.ViewLaterPage));
                break;

            case "History":
                App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Video.HistoryPage));
                break;

            default:
                break;
            }
            AccountFlyout.Hide();
        }
Exemplo n.º 9
0
 /// <summary>
 /// 播放视频列表
 /// </summary>
 /// <param name="aid">AV号</param>
 /// <param name="videoList">播放列表</param>
 public void PlayVideoList(int aid, object sender, List <VideoDetail> videoList)
 {
     CurrentSubPageControl.CheckSubReplyPage();
     SelectedSideMenuItem = null;
     if (sender != null && IsEnableAnimation)
     {
         var image = VisualTreeExtension.VisualTreeFindName <FrameworkElement>((FrameworkElement)sender, "VideoCover");
         ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("VideoConnectedAnimation", image);
     }
     if (App._isTabletMode)
     {
         CurrentTopPanel.SetSelectedItem(AppMenuItemType.Line);
         TabletMainPage.Current.NavigateToPage(AppMenuItemType.VideoPlayer, new Tuple <int, List <VideoDetail> >(aid, videoList));
     }
     else
     {
         CurrentSidePanel.SetSelectedItem(AppMenuItemType.Line);
         CurrentPagePanel.NavigateToPage(AppMenuItemType.VideoPlayer, new Tuple <int, List <VideoDetail> >(aid, videoList));
     }
 }
Exemplo n.º 10
0
        private void OnMoveThumbDragDelta(object sender, DragDeltaEventArgs e)
        {
            var window = VisualTreeExtension.FindMDIWindow(this);

            if (window != null)
            {
                if (window.WindowState == WindowState.Maximized)
                {
                    window.Normalize();
                }

                if (window.WindowState != WindowState.Minimized)
                {
                    window.LastLeft = Canvas.GetLeft(window);
                    window.LastTop  = Canvas.GetTop(window);

                    Canvas.SetLeft(window, window.LastLeft + e.HorizontalChange);
                    Canvas.SetTop(window, window.LastTop + e.VerticalChange);
                }
            }
        }
Exemplo n.º 11
0
        private void MdiWindow_Loaded(object sender, RoutedEventArgs e)
        {
            MdiWindow window  = sender as MdiWindow;
            var       content = VisualTreeExtension.FindContent(window);

            if (content != null)
            {
                window.MinHeight = content.MinHeight + Content_Height_Margin;
                window.MinWidth  = content.MinWidth + Content_Width_Margin;

                window.Height = Math.Max(content.ActualHeight + Content_Height_Margin, ActualHeight);
                window.Width  = Math.Max(content.ActualWidth + Content_Width_Margin, ActualWidth);
                if (window.PreviousHeight == 0)
                {
                    window.PreviousHeight = window.Height;
                }
                if (window.PreviousWidth == 0)
                {
                    window.PreviousWidth = window.Width;
                }
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// 播放番剧
 /// </summary>
 /// <param name="epid">AV号</param>
 /// <param name="sender">触发控件(用于查找封面以实现连接动画)</param>
 public void PlayBangumi(int epid, object sender = null, bool isEp = false)
 {
     CurrentSubPageControl.CheckSubReplyPage();
     SelectedSideMenuItem = null;
     if (sender != null && IsEnableAnimation)
     {
         var image = VisualTreeExtension.VisualTreeFindName <FrameworkElement>((FrameworkElement)sender, "VideoCover");
         if (image != null)
         {
             string animationName = "BangumiConnectedAnimation" + Guid.NewGuid().ToString("N");
             ConnectAnimationName = animationName;
             ConnectedAnimationService.GetForCurrentView().PrepareToAnimate(animationName, image);
         }
         else
         {
             ConnectAnimationName = "";
         }
     }
     if (App._isTabletMode)
     {
         CurrentTopPanel.SetSelectedItem(AppMenuItemType.Line);
         TabletMainPage.Current.NavigateToPage(AppMenuItemType.VideoPlayer, new Tuple <int, bool>(epid, isEp));
     }
     else
     {
         CurrentSidePanel.SetSelectedItem(AppMenuItemType.Line);
         if (isEp)
         {
             CurrentPagePanel.NavigateToPage(AppMenuItemType.BangumiPlayer, new Tuple <int, bool>(epid, isEp));
         }
         else
         {
             CurrentPagePanel.NavigateToPage(AppMenuItemType.BangumiPlayer, epid);
         }
     }
 }