Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should define the playing state in you viewmodel (Playing/Stopped), and bind Button.Style to that property using a converter. In your converter, return a different style (taken from App.Current.Resources) based on the current state.</p> <p><strong>Edit:</strong></p> <p>Here's an example of your converter should look like:</p> <pre><code>public class StateStyleConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return (PlaybackState)value == PlaybackState.Playing ? App.Current.Resources["RoundPlay"] : App.Current.Resources["RoundStop"]; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } </code></pre> <p>In this example, PlaybackState is an enum:</p> <pre><code>public enum PlaybackState { Playing, Stopped } </code></pre> <p>Then you should add the state property to your view model (The part where you notify the change depends on the framework you are using for MVVM):</p> <pre><code>private PlaybackState state; public PlaybackState State { get { return state; } set { state = value; RaiseNotifyPropertyChanged("State"); } } </code></pre> <p>Declare your converter in XAML:</p> <pre><code>&lt;UserControl.Resources&gt; &lt;converters:StateStyleConverter x:Key="StateStyleConverter"/&gt; &lt;/UserControl.Resources&gt; </code></pre> <p>And finally bind it to the button:</p> <pre><code>&lt;Button Width="72" Height="72" Style="{Binding State, Converter={StaticResource StateStyleConverter}}" DataContext="{Binding ElementName=this, Path=DataContext}" cmd:ButtonBaseExtensions.Command="{Binding PlayStopCommand}" /&gt; </code></pre>
 

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