Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use ToggleSwitch with MVVM Light in WP7?
    primarykey
    data
    text
    <p>I am trying to use a ToggleSwitch with MVVM Light in a Wp7 app.</p> <p>In the view I have:</p> <pre><code>&lt;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" &gt; </code></pre> <p>The ViewModel contains:</p> <pre><code>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; } } </code></pre> <p>AccuracyText and AccuracyHigh fire to get the appropriate values. </p> <p>My difficulty is trying to trap the "state changed" event; Checked and Unchecked. If I bind these with something like: Checked="{Binding Path=AccuracyChanged}" I get a runtime error telling me the markup is wrong.</p> <p>I also unsuccessfully tried a trigger:</p> <pre><code> &lt;i:Interaction.Triggers&gt; &lt;i:EventTrigger EventName="Checked"&gt; &lt;GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding AccuracyChanged}"/&gt; &lt;/i:EventTrigger&gt; &lt;/i:Interaction.Triggers&gt; &lt;/toolkit:ToggleSwitch&gt; </code></pre> <p>I could use RadioButton which work just fine with </p> <pre><code>&lt;RadioButton Content="Up" x:Name="radioButton1" GroupName="UpDown" Width="119" /&gt; &lt;RadioButton IsChecked="{Binding UpDown, Mode=TwoWay}" Content="Down" x:Name="radioButton2" GroupName="UpDown" /&gt; public bool UpDown { get { bool ud = settings.UpDown.ToLower() == "u" ? true : false; return ud; } set { settings.UpDown = value == true ? "U" : "D"; settings.Save(); } } </code></pre> <p>but a ToggleSwitch looks better (IMHO)</p> <p>Any suggestions appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload