Example #1
0
        private static void HandleToggleButtonMouseButtonChanged(object sender, MouseButtonEventArgs e)
        {
            ToggleButton tb = sender as ToggleButton;

            if (tb == null)
            {
                return;
            }

            bool isMomentary         = GetIsMomentary(tb);
            bool isToggleOnMouseDown = GetIsToggleOnMouseDown(tb);

            if (e.ButtonState == MouseButtonState.Pressed)
            {
                if (isMomentary || isToggleOnMouseDown)
                {
                    tb.IsChecked = true;
                }
                if (isMomentary)
                {
                    tb.CaptureMouse();
                }
            }
            else
            {
                if (isMomentary)
                {
                    tb.IsChecked = false;
                    tb.ReleaseMouseCapture();
                }
            }

            e.Handled = true;
        }