I am trying to use ToggleSwitch with MVVM Light in a Wp7 application.
In the view, I have:
<toolkit:ToggleSwitch x:Name="toggleAccuracy" Content="{Binding AccuracyText, Mode=TwoWay}" IsChecked="{Binding AccuracyHigh, Mode=TwoWay}" IsEnabled="True" Header="Accuracy" Margin="8,0" Height="140" VerticalAlignment="Top" >
ViewModel contains:
private bool _AccuracyHigh = true; public bool AccuracyHigh { get { return _AccuracyHigh; } set { _AccuracyHigh = value; } } private string _AccuracyText = "High"; public string AccuracyText { get { return _AccuracyText; } set { _AccuracyText = value; } }
AccuracyText and AccuracyHigh fire to get the appropriate values.
My difficulty is trying to capture the "state changed" event; Checked and removed. If I associate them with something like: Checked = "{Binding Path = AccuracyChanged}" I get a runtime error indicating that the markup is incorrect.
I also tried unsuccessfully to trigger the trigger:
<i:Interaction.Triggers> <i:EventTrigger EventName="Checked"> <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding AccuracyChanged}"/> </i:EventTrigger> </i:Interaction.Triggers> </toolkit:ToggleSwitch>
I could use RadioButton, which works great with
<RadioButton Content="Up" x:Name="radioButton1" GroupName="UpDown" Width="119" /> <RadioButton IsChecked="{Binding UpDown, Mode=TwoWay}" Content="Down" x:Name="radioButton2" GroupName="UpDown" /> public bool UpDown { get { bool ud = settings.UpDown.ToLower() == "u" ? true : false; return ud; } set { settings.UpDown = value == true ? "U" : "D"; settings.Save(); } }
but ToggleSwitch looks better (IMHO)
Any suggestions appreciated.
source share