Ejemplo n.º 1
0
        /// <summary>
        /// IsCheckedProperty property changed handler.
        /// </summary>
        /// <param name="d">ToggleButton that changed its IsChecked.</param>
        /// <param name="e">DependencyPropertyChangedEventArgs.</param>
        private static void OnIsCheckedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ToggleButton source = d as ToggleButton;

            System.Diagnostics.Debug.Assert(source != null,
                                            "The source is not an instance of ToggleButton!");

            System.Diagnostics.Debug.Assert(typeof(bool?).IsInstanceOfType(e.NewValue) || (e.NewValue == null),
                                            "The value is not an instance of bool?!");
            bool?value = (bool?)e.NewValue;

            // Raise the appropriate changed event
            RoutedEventArgs args = new RoutedEventArgs()
            {
                OriginalSource = source
            };

            if (value == true)
            {
                source.OnChecked(args);
            }
            else if (value == false)
            {
                source.OnUnchecked(args);
            }
            else
            {
                source.OnIndeterminate(args);
            }
        }
Ejemplo n.º 2
0
        // Token: 0x060060EC RID: 24812 RVA: 0x001B2F60 File Offset: 0x001B1160
        private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ToggleButton toggleButton = (ToggleButton)d;
            bool?        oldValue     = (bool?)e.OldValue;
            bool?        flag         = (bool?)e.NewValue;
            ToggleButtonAutomationPeer toggleButtonAutomationPeer = UIElementAutomationPeer.FromElement(toggleButton) as ToggleButtonAutomationPeer;

            if (toggleButtonAutomationPeer != null)
            {
                toggleButtonAutomationPeer.RaiseToggleStatePropertyChangedEvent(oldValue, flag);
            }
            if (flag == true)
            {
                toggleButton.OnChecked(new RoutedEventArgs(ToggleButton.CheckedEvent));
            }
            else if (flag == false)
            {
                toggleButton.OnUnchecked(new RoutedEventArgs(ToggleButton.UncheckedEvent));
            }
            else
            {
                toggleButton.OnIndeterminate(new RoutedEventArgs(ToggleButton.IndeterminateEvent));
            }
            toggleButton.UpdateVisualState();
        }
        /// <summary>
        ///     Called when IsChecked is changed on "d."
        /// </summary>
        /// <param name="d">The object on which the property was changed.</param>
        /// <param name="e">EventArgs that contains the old and new values for this property</param>
        private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ToggleButton button   = (ToggleButton)d;
            bool?        oldValue = (bool?)e.OldValue;
            bool?        newValue = (bool?)e.NewValue;

            //doing soft casting here because the peer can be that of RadioButton and it is not derived from
            //ToggleButtonAutomationPeer - specifically to avoid implementing TogglePattern
            ToggleButtonAutomationPeer peer = UIElementAutomationPeer.FromElement(button) as ToggleButtonAutomationPeer;

            if (peer != null)
            {
                peer.RaiseToggleStatePropertyChangedEvent(oldValue, newValue);
            }

            if (newValue == true)
            {
                button.OnChecked(new RoutedEventArgs(CheckedEvent));
            }
            else if (newValue == false)
            {
                button.OnUnchecked(new RoutedEventArgs(UncheckedEvent));
            }
            else
            {
                button.OnIndeterminate(new RoutedEventArgs(IndeterminateEvent));
            }

            button.UpdateVisualState();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// IsCheckedProperty property changed handler.
        /// </summary>
        /// <param name="d">ToggleButton that changed its IsChecked.</param>
        /// <param name="e">DependencyPropertyChangedEventArgs.</param>
        private static void OnIsCheckedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ToggleButton source = d as ToggleButton;

            System.Diagnostics.Debug.Assert(source != null,
                                            "The source is not an instance of ToggleButton!");

            System.Diagnostics.Debug.Assert(typeof(bool?).IsInstanceOfType(e.NewValue) || (e.NewValue == null),
                                            "The value is not an instance of bool?!");
            bool?value = (bool?)e.NewValue;

            // Raise the appropriate changed event
            RoutedEventArgs args = new RoutedEventArgs();

            args.OriginalSource = source; // like beta1 (and unit test confirmed)
            if (value == true)
            {
                source.OnChecked(args);
            }
            else if (value == false)
            {
                source.OnUnchecked(args);
            }
            else
            {
                source.OnIndeterminate(args);
            }

            // Raising UIA Automation Event
            ToggleButtonAutomationPeer peer = source.AutomationPeer as ToggleButtonAutomationPeer;

            if (peer != null)
            {
                peer.RaiseToggleStateChanged();
            }
        }