예제 #1
0
        /// <summary>
        /// Coerce Callback method of the SelectedIndex Dependency Property.
        /// </summary>
        /// <param name="sender">The instance of the class of which the SelectedIndex property is about to change.</param>
        /// <param name="value">The proposed new value for the SelectedIndex property.</param>
        /// <returns>The actual new value for the SelectedIndex property.</returns>
        private static object CoerceSelectedIndex(DependencyObject sender, object value)
        {
            PageViewer subject  = (PageViewer)sender;
            int        newValue = (int)value;

            if (newValue < -1 || newValue > subject.Items.Count - 1)
            {
                return(-1);
            }

            return(value);
        }
예제 #2
0
        /// <summary>
        /// Property Changed Callback method of the Items Dependency Property.
        /// </summary>
        /// <param name="sender">The instance of the class that had the Items property changed.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void OnItemsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            PageViewer subject = (PageViewer)sender;
            ObservableCollection <PageViewerItem> newValue = (ObservableCollection <PageViewerItem>)e.NewValue;
            ObservableCollection <PageViewerItem> oldValue = (ObservableCollection <PageViewerItem>)e.OldValue;

            if (oldValue != null)
            {
                oldValue.CollectionChanged -= subject.Items_CollectionChanged;
                subject.SetOldItemsOwner(oldValue);
            }

            if (newValue != null)
            {
                newValue.CollectionChanged += subject.Items_CollectionChanged;
                subject.SetNewItemsOwner(newValue);
            }
        }
예제 #3
0
        /// <summary>
        /// Property Changed Callback method of the SelectedItem Dependency Property.
        /// </summary>
        /// <param name="sender">The instance of the class that had the SelectedItem property changed.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void OnSelectedItemChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            PageViewer     subject  = (PageViewer)sender;
            PageViewerItem newValue = (PageViewerItem)e.NewValue;
            PageViewerItem oldValue = (PageViewerItem)e.OldValue;

            subject.IsSettingSelection = true;

            if (oldValue != null)
            {
                oldValue.FreeContent();
                oldValue.IsSelected = false;
            }

            if (newValue != null)
            {
                newValue.InitializeContent();
                newValue.IsSelected = true;
            }

            subject.IsSettingSelection = false;
        }