/// <summary>
        /// Fired the the object is ready, setup the scroll detection.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EndDetectingListView_Loaded(object sender, global::Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Stop listening to the event. We only want to do this once.
            Loaded -= EndDetectingListView_Loaded;

            // Get the scroll bars
            List <DependencyObject> scrollBars = new List <DependencyObject>();

            UiControlHelpers <ScrollBar> .RecursivelyFindElement(this, ref scrollBars);

            // Find the scrollbar we want. Fun fact. Since in the scollviewer (which is in the list) the scrollContentPresenter is before the
            // main scrollbars we will find scrollbars of the header before ours. Ours should always be the last scrollbars in the list.
            // SO KEEP GOING DON'T BREAK until we find the last vertical scrollbar.
            foreach (DependencyObject dObject in scrollBars)
            {
                if (((ScrollBar)dObject).Orientation == Orientation.Vertical)
                {
                    m_listeningScrollBar = (ScrollBar)dObject;
                }
            }

            // Make sure we found it
            if (m_listeningScrollBar == null)
            {
                throw new Exception("Failed to find the scroll bar!");
            }

            // Add the listener
            m_listeningScrollBar.ValueChanged += ScrollBar_ValueChanged;
        }
예제 #2
0
        private void SimpleTextButton_Loaded(object sender, RoutedEventArgs e)
        {
            // Unregister for loaded events so we don't do this many times.
            Loaded -= SimpleTextButton_Loaded;

            // First, try to get the main root grid.
            List <DependencyObject> uiElements = new List <DependencyObject>();

            UiControlHelpers <Grid> .RecursivelyFindElement(this, ref uiElements);

            if (uiElements.Count != 1)
            {
                throw new Exception("Found too many or too few grids!");
            }

            // Grab it
            ui_contentRoot = (Grid)uiElements[0];

            // Next try to find the text block
            uiElements.Clear();
            UiControlHelpers <TextBlock> .RecursivelyFindElement(this, ref uiElements);

            if (uiElements.Count != 1)
            {
                throw new Exception("Found too many or too few textblocks!");
            }

            // Grab it
            ui_buttonText = (TextBlock)uiElements[0];

            // If the desired text already exists set it
            if (m_currentButtonText != null)
            {
                ui_buttonText.Text = m_currentButtonText;
            }

            // Set the normal text color
            ui_buttonText.Foreground = new SolidColorBrush(m_normalTextColor);

            // Grab the current accent color
            m_accentColor = ((SolidColorBrush)Application.Current.Resources["SystemControlBackgroundAccentBrush"]).Color;

            // Next create our storyboards and animations
            m_colorStoryboard = new Storyboard();
            m_colorAnimation  = new ColorAnimation();
            m_colorStoryboard.Children.Add(m_colorAnimation);

            // Set them up.
            Storyboard.SetTarget(m_colorStoryboard, ui_buttonText);
            Storyboard.SetTargetProperty(m_colorStoryboard, "(TextBlock.Foreground).(SolidColorBrush.Color)");
            m_animateInDuration  = new Duration(new TimeSpan(0, 0, 0, 0, 200));
            m_animateOutDuration = new Duration(new TimeSpan(0, 0, 0, 0, 400));

            // Last add our events to the grid
            ui_contentRoot.PointerPressed  += ContentRoot_PointerPressed;
            ui_contentRoot.Tapped          += ContentRoot_Tapped;
            ui_contentRoot.PointerCanceled += ContentRoot_PointerCanceled;
            ui_contentRoot.PointerExited   += ContentRoot_PointerExited;
            ui_contentRoot.PointerReleased += ContentRoot_PointerReleased;
        }