I have a button with 3 States Start/Resume/Pause.
1 Is this a good pattern to solve this or maybe there is some toggle button mode that I am not aware of?
private void cmdStart_Click(object sender, RoutedEventArgs e)
{
if (m_end)
{
// Reset the game.
m_end = false;
cmdStart.Content = "Pause Game";
// Update the display.
}
else
{
if (m_pause)
{
m_bombTimer.Start();
foreach (var storyboard in m_storyboards)
{
// resume all animations
}
status.Visibility = System.Windows.Visibility.Collapsed;
m_pause = false;
cmdStart.Content = "Pause Game";
}
else
{
m_bombTimer.Stop();
foreach (var storyboard in m_storyboards)
{
// pause all animations
}
status.Visibility = System.Windows.Visibility.Visible;
cmdStart.Content = "Resume Game";
m_pause = true;
}
}
2 How to get rid off focus of button in Silverlight? I do not want to user to click button pressing enter.
Silverlight provides a built-in state machine to assist you, called the Visual State Manager. It would be a bit involved for me to try to provide a full sample here, but in essence, you can create your states explicitly and each state has a state value, which is a storyboard of duration 0, and a transition, which can be any number of animations. In the states, you simply define the desired control states – for example, you can ask that the control is collapsed, etc. In the transitions, you can kick off your animations. Furthermore, you can bind to the states using a custom visual state manager such that when the states change, you trigger changes in content.
What’s nice here is there is a clean separation of code from the UI and you simply transition to states and encapsulate the logic elsewhere.
More reading on the VSM:
http://blogs.infosupport.com/blogs/alexb/archive/2010/04/02/silverlight-4-using-the-visualstatemanager-for-state-animations-with-mvvm.aspx
http://blogs.silverlight.net/blogs/justinangel/archive/2008/12/25/custom-vsm-visualstatemanagers-in-silverlight-2-0.aspx