Ejemplo n.º 1
0
        //Monitor and handle the scroll viewer
        private async void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
        {
            try
            {
                //Get current scroll item
                int CurrentOffSetId = EventsScrollViewer.GetCurrentOffsetIndex(ListView_Items);
                if (CurrentOffSetId < 0)
                {
                    return;
                }

                //Update the current item count
                AppVariables.CurrentShownItemCount = CurrentOffSetId + 1;
                if (stackpanel_Header.Visibility == Visibility.Visible || AppVariables.CurrentTotalItemsCount == 0)
                {
                    textblock_StatusCurrentItem.Text = AppVariables.CurrentShownItemCount.ToString();
                }
                else
                {
                    textblock_StatusCurrentItem.Text = AppVariables.CurrentShownItemCount + "/" + AppVariables.CurrentTotalItemsCount;
                }

                //Update the shown item content
                await EventsScrollViewer.ScrollViewerUpdateContent(ListView_Items, CurrentOffSetId);
            }
            catch { }
        }
Ejemplo n.º 2
0
        //Monitor and handle the scroll viewer
        private async void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
        {
            try
            {
                //Get current scroll item
                VirtualizingStackPanel virtualizingStackPanel = AVFunctions.FindVisualChild <VirtualizingStackPanel>(ListView_Items);
                Int32 CurrentOffSetId = (virtualizingStackPanel.Orientation == Orientation.Horizontal) ? (Int32)virtualizingStackPanel.HorizontalOffset : (Int32)virtualizingStackPanel.VerticalOffset;

                //Update the current item count
                textblock_StatusCurrentItem.Tag = (CurrentOffSetId + 1).ToString();
                Int32 HeaderTargetSize  = Convert.ToInt32(stackpanel_Header.Tag);
                Int32 HeaderCurrentSize = Convert.ToInt32(stackpanel_Header.Height);
                if (HeaderCurrentSize == HeaderTargetSize || AppVariables.CurrentTotalItemsCount == 0)
                {
                    textblock_StatusCurrentItem.Text = textblock_StatusCurrentItem.Tag.ToString();
                }
                else
                {
                    textblock_StatusCurrentItem.Text = textblock_StatusCurrentItem.Tag.ToString() + "/" + AppVariables.CurrentTotalItemsCount;
                }

                //Update the shown item content
                await EventsScrollViewer.ScrollViewerUpdateContent(ListView_Items, CurrentOffSetId);

                //Check if new items need to be loaded
                await EventsScrollViewer.ScrollViewerAddItems(ListView_Items, CurrentOffSetId);
            }
            catch { }
        }
Ejemplo n.º 3
0
        public async Task AdjustItemsScrollingDirection(Int32 Direction)
        {
            try
            {
                if (!AdjustingItemsScrollingDirection)
                {
                    if (Direction == 0)
                    {
                        Style TargetStyle = (Style)Application.Current.Resources["ListViewVertical"];
                        if (ListView_Items.Style != TargetStyle)
                        {
                            AdjustingItemsScrollingDirection = true;
                            Double[] CurrentOffset = EventsScrollViewer.GetCurrentOffset(ListView_Items);

                            ScrollViewer virtualScrollViewer = AVFunctions.FindVisualChild <ScrollViewer>(ListView_Items);
                            if (virtualScrollViewer != null)
                            {
                                ListView_Items.Style              = TargetStyle;
                                ListView_Items.ItemTemplate       = (DataTemplate)Application.Current.Resources["ListViewItemsVertical" + Convert.ToInt32(AppVariables.ApplicationSettings["ListViewStyle"])];
                                ListView_Items.ItemContainerStyle = (Style)Application.Current.Resources["ListViewItemStretchedVertical"];

                                await Task.Delay(10);

                                virtualScrollViewer.ChangeView(CurrentOffset[1], (CurrentOffset[0] + 2), null);
                                //Debug.WriteLine("Scrolling to vertical:" + (CurrentOffset[0] + 2));
                            }

                            //Adjust Status Current Item margin
                            button_StatusCurrentItem.Margin = new Thickness(6, 0, 0, 6);

                            AdjustingItemsScrollingDirection = false;
                        }
                    }
                    else if (Direction == 1)
                    {
                        Style TargetStyle = (Style)Application.Current.Resources["ListViewHorizontal"];
                        if (ListView_Items.Style != TargetStyle)
                        {
                            AdjustingItemsScrollingDirection = true;
                            Double[] CurrentOffset = EventsScrollViewer.GetCurrentOffset(ListView_Items);

                            ScrollViewer virtualScrollViewer = AVFunctions.FindVisualChild <ScrollViewer>(ListView_Items);
                            if (virtualScrollViewer != null)
                            {
                                ListView_Items.Style              = TargetStyle;
                                ListView_Items.ItemTemplate       = (DataTemplate)Application.Current.Resources["ListViewItemsHorizontal" + Convert.ToInt32(AppVariables.ApplicationSettings["ListViewStyle"])];
                                ListView_Items.ItemContainerStyle = (Style)Application.Current.Resources["ListViewItemStretchedHorizontal"];

                                await Task.Delay(10);

                                virtualScrollViewer.ChangeView((CurrentOffset[1] + 2), CurrentOffset[0], null);
                                //Debug.WriteLine("Scrolling to horizontal:" + (CurrentOffset[1] + 2));
                            }

                            //Adjust Status Current Item margin
                            if (AVFunctions.DevMobile())
                            {
                                button_StatusCurrentItem.Margin = new Thickness(6, 0, 0, 6);
                            }
                            else
                            {
                                button_StatusCurrentItem.Margin = new Thickness(16, 0, 0, 16);
                            }

                            AdjustingItemsScrollingDirection = false;
                        }
                    }
                    else if (Direction == 2)
                    {
                        Rect ScreenSize = AVFunctions.AppWindowResolution();
                        if (ScreenSize.Width > ScreenSize.Height)
                        {
                            await AdjustItemsScrollingDirection(1);
                        }
                        else
                        {
                            await AdjustItemsScrollingDirection(0);
                        }
                    }
                }
            }
            catch { AdjustingItemsScrollingDirection = false; }
        }
Ejemplo n.º 4
0
        //Adjust the news items scrolling direction
        public async Task AdjustItemsScrollingDirection(int Direction)
        {
            try
            {
                if (Direction == 0)
                {
                    Style TargetStyle = (Style)Application.Current.Resources["ListViewVertical"];
                    if (ListView_Items.Style != TargetStyle)
                    {
                        ScrollViewer virtualScrollViewer = AVFunctions.FindVisualChild <ScrollViewer>(ListView_Items);
                        if (virtualScrollViewer != null)
                        {
                            object CurrentOffset = EventsScrollViewer.GetCurrentOffsetItem(ListView_Items);
                            ListView_Items.Style              = TargetStyle;
                            ListView_Items.ItemTemplate       = (DataTemplate)Application.Current.Resources["ListViewItemsVertical" + Convert.ToInt32(AppVariables.ApplicationSettings["ListViewStyle"])];
                            ListView_Items.ItemContainerStyle = (Style)Application.Current.Resources["ListViewItemStretchedVertical"];

                            await Task.Delay(100);

                            ListView_Items.ScrollIntoView(CurrentOffset);
                            System.Diagnostics.Debug.WriteLine("Changed listview to vertical style.");
                        }

                        //Adjust Status Current Item margin
                        button_StatusCurrentItem.Margin = new Thickness(6, 0, 0, 6);
                    }
                }
                else if (Direction == 1)
                {
                    Style TargetStyle = (Style)Application.Current.Resources["ListViewHorizontal"];
                    if (ListView_Items.Style != TargetStyle)
                    {
                        ScrollViewer virtualScrollViewer = AVFunctions.FindVisualChild <ScrollViewer>(ListView_Items);
                        if (virtualScrollViewer != null)
                        {
                            object CurrentOffset = EventsScrollViewer.GetCurrentOffsetItem(ListView_Items);
                            ListView_Items.Style              = TargetStyle;
                            ListView_Items.ItemTemplate       = (DataTemplate)Application.Current.Resources["ListViewItemsHorizontal" + Convert.ToInt32(AppVariables.ApplicationSettings["ListViewStyle"])];
                            ListView_Items.ItemContainerStyle = (Style)Application.Current.Resources["ListViewItemStretchedHorizontal"];

                            await Task.Delay(100);

                            ListView_Items.ScrollIntoView(CurrentOffset);
                            System.Diagnostics.Debug.WriteLine("Changed listview to horizontal style.");
                        }

                        //Adjust Status Current Item margin
                        if (AVFunctions.DevMobile())
                        {
                            button_StatusCurrentItem.Margin = new Thickness(6, 0, 0, 6);
                        }
                        else
                        {
                            button_StatusCurrentItem.Margin = new Thickness(16, 0, 0, 16);
                        }
                    }
                }
                else if (Direction == 2)
                {
                    Rect ScreenSize = AVFunctions.AppWindowResolution();
                    if (ScreenSize.Width > ScreenSize.Height)
                    {
                        await AdjustItemsScrollingDirection(1);
                    }
                    else
                    {
                        await AdjustItemsScrollingDirection(0);
                    }
                }
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("Failed to adjust item scrolling direction.");
            }
        }