I m stuck with a problem. I want to change the background image of button on runtime. I got the solution for changing the color but i want to change the image.
The c
Utilize VisualStates for this kind of UI state switching. Your code behind would look like this:
public void buttonCase(object sender, RoutedEventArgs e)
{
if (((App)App.Current).appControler.m_Mode == Controller.textMode.Letters)
{
((App)App.Current).appControler.buttonCase(sender, e);
switch (((App)App.Current).appControler.m_case)
{
case Controller.caseMode.Upper:
VisualStateManager.GoToState( this, "UpperCase", true );
break;
case Controller.caseMode.Lower:
VisualStateManager.GoToState( this, "LowerCase", true );
break;
}
}
}
And your xaml would look like this:
Visible
Collapsed
40
I wrote the code as an answer to a similar question here:toggle button with different images
I know that defining VisualStates can look quite cumbersome, but in the end you can keep your code behind quite clean from switching visual appearance of all the ui bits and pieces.