Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToggleSwitch and ToggleSwitchButton works differently depending whether user clicked on it or dragged it #3458

Closed
DomasM opened this issue Feb 21, 2019 · 1 comment
Assignees
Labels
Milestone

Comments

@DomasM
Copy link
Contributor

DomasM commented Feb 21, 2019

ToggleSwitch and ToggleSwitchButton works differently depending whether user clicked on it or dragged it

To Reproduce
xaml:

<StackPanel Orientation="Vertical">
<mah:ToggleSwitch  IsChecked="{Binding IsA, Mode=TwoWay}" OnLabel="A" OffLabel="Not A"></mah:ToggleSwitch>
 <mah:ToggleSwitchButton  IsChecked="{Binding IsA, Mode=TwoWay}" >A?</mah:ToggleSwitchButton>
 <ToggleButton  IsChecked="{Binding IsA, Mode=TwoWay}" >A??</ToggleButton>
<CheckBox  IsChecked="{Binding IsA, Mode=TwoWay}" >A??</CheckBox>
 </StackPanel>

view model (PropertyChanged is injected by Fody.PropertyChanged)

 public class TestViewModel : INotifyPropertyChanged {
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged ([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null) {
            PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (propertyName));
        }



        private bool _IsA { get; set; }
        public bool IsA { get { return _IsA; } set { MaybeSetA (value); } }

        private void MaybeSetA (bool value) {
            var rand = new Random ();
            if (rand.NextDouble () > 0.5) {
                Trace.WriteLine ("set new value");
                _IsA = value;
            } else {
                Trace.WriteLine ("ignore new value");
            }
        }

    }

Expected behavior
I expect state of the control to change depending whether MaybeSetA() decides to accept new value or not. This is so if user clicks on ToggleSwitch/ToggleSwitchButton, but not if user drags indicator. ToggleButton and CheckBox work as expected (but they are not part of MahApps). All the controls should be in the same state all the time, as they are bound to the same property.
Screenshots

image

Environment(please complete the following information):

  • MahApps.Metro, tested both with newest and newest -pre

Repo
https://github.com/DomasM/TestMahAppsToggleSwitch
run Update-Package Fody -Reinstall after clone

@punker76 punker76 added the Bug label Feb 22, 2019
@punker76 punker76 self-assigned this Feb 22, 2019
@DomasM
Copy link
Contributor Author

DomasM commented Feb 22, 2019

Additionally, in case of ToggleSwitch, on label and off label are shown correctly (i.e. bound to property).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants