示例#1
0
        /// <summary>
        /// Invoked when the effective property value of the ViewMode property changes.
        /// </summary>
        /// <param name="dependencyObject">The DependencyObject on which the property has changed value.</param>
        /// <param name="dependencyPropertyChangedEventArgs">Event data that is issued by any event that tracks changes to the effective value of this
        /// property.</param>
        static void OnViewModePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // Extract the ViewButton and the new view mode from the property change event arguments.
            ViewButton viewButton = dependencyObject as ViewButton;
            ViewMode   viewMode   = (ViewMode)dependencyPropertyChangedEventArgs.NewValue;

            // This uses a table of image sources to match the image on the button with the mode selected.
            viewButton.Icon = new Image()
            {
                Source = ViewButton.imageSourceTable[viewMode]
            };
        }
示例#2
0
        /// <summary>
        /// Invoked when the effective property value of the Value property changes.
        /// </summary>
        /// <param name="dependencyObject">The DependencyObject on which the property has changed value.</param>
        /// <param name="dependencyPropertyChangedEventArgs">Event data that is issued by any event that tracks changes to the effective value of this
        /// property.</param>
        static void OnValuePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // Extract the ViewButton and the new view value from the property change event arguments.
            ViewButton viewButton = dependencyObject as ViewButton;
            Int32      viewValue  = (Int32)dependencyPropertyChangedEventArgs.NewValue;

            // This will snap the slider into a distinct position for a viewing mode.  Note that any minimum or maximum can be used for the slider control and the
            // scaling calculations will adjust.
            foreach (Range range in ViewButton.viewRange)
            {
                if (range.Minimum <= viewValue && viewValue < range.Maximum)
                {
                    viewButton.ViewMode = range.ViewMode;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the ViewButton class.
        /// </summary>
        public ViewButton()
        {
            // This will handle the part of the Gadget that acts like a button when it is clicked.
            this.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(this.OnButtonClick));

            // If the actual value of a property hasn't changed, then the property change handler isn't called.  This is a problem on initialization because if you
            // try to set the property to an explicit value and that value is the same as the default for that property, then there's no implicit way to call the
            // property change handler.  This trick will force the button into a known state by explicitly calling the event handler.
            ViewMode viewMode = (ViewMode)ViewButton.ViewModeProperty.DefaultMetadata.DefaultValue;

            ViewButton.OnViewModePropertyChanged(this, new DependencyPropertyChangedEventArgs(ViewButton.ViewModeProperty, null, viewMode));

            // This is the header for the button which is normally invisible when it is parked on the far side of the toolbar.  It become visible on the right side
            // and when it overflows.
            this.Header = Properties.Resources.Views;

            // This provides the tool tip for the button.
            this.ToolTip = Properties.Resources.ChangeViewToolTip;
        }