Silverlight – ToggleButton Control VisualStateManager: Handling multiple hover status

Referring to my previous question (Silverlight MVVM Confusion: Updating Image Based on State), I started to adopt a new method. I left the existing question because I don’t want to be sure My new method is the correct answer (I still welcome comments on my original question).

If you read my previous question, please feel free to skip this paragraph: I am trying to build one Control, providing a function similar to an audio play button. When the application is in “Play” mode, the application should display the “Pause.png” image. When it is paused, it should display the “Play.png” image. There are two more An additional image to illustrate any state when the user hovers over the control (for example, “Play_Hover.png” and “Pause_Hover.png”). The state is determined by the IsPlaying property in my view model.

< p>I decided to use ToggleButton to determine the image to be displayed based on the current state. Remember, when IsPlaying is false, the play button will be displayed, and if it is true, the pause button will be displayed. Therefore, I came up with the following XAML. It’s Working principle except hovering:

 xmlns="http://schemas.microsoft.com/winfx/ 2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/ expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity; assembly=System.Windows.Interactivity"
mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidt h="200">






How do you States provide different hover images? If I add a hover state to the CommonStates group, I will be able to consider only the hover of one of the states (checked or unchecked).

< /div>

When using togglebutton, it is impossible to have different hover/mouse hover states, because this is common for buttons.
The common state is Normal (the one you saw first) , Mouseover, Pressed and Disabled

Other states are related to checked, unchecked, or intermediate. Here, you can set different images for various states, etc. The mouse hover will always roll back To the public state.

If you must have this feature, you can create your own custom control for this, and handle the mouse hover animation based on the active state. This will require more code in the backend because you Need to redefine the button class of this object and insert various state tests to allow animation to be played for each state. I just don’t know if it’s worth the effort.

Referring to my previous question (Silverlight MVVM Confusion: Updating Image Based on State), I started to adopt a new method. I left the existing question because I don’t want to be sure that my new method is the correct answer (I still welcome comments on my original question).

If you read my previous question, please feel free to skip this paragraph: I am trying to build a control that provides similar audio playback The function of the button. When the application is in “Play” mode, the application should display the “Pause.png” image. When it is paused, it should display the “Play.png” image. There are two additional images to illustrate when the user Any state when hovering over the control (for example, “Play_Hover.png” and “Pause_Hover.png”). The state is determined by the IsPlaying property in my view model.

I decided to use ToggleButton according to The current state determines the image to be displayed. Remember that when IsPlaying is false, the play button will be displayed, and if it is true, the pause button will be displayed. Therefore, I came up with the following XAML. It works except for hovering: /p>

 xmlns="http://schemas.microsoft.com/winfx/2006/xa ml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/ blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly= System.Windows.Interactivity"
mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="200">

< Style x:Key="MyButtonStyle" TargetType="ToggleButton">























Visible


< /ObjectAnimationUsingKeyFrames>


< br /> Collapsed






< br />


< Visibility>Visible






Collapsed





















How do you provide different hover for these two states image? If I add a hover state to the CommonStates group, I will be able to consider only the hover of one of the states (checked or unchecked).

Use It is impossible to have different hover/mouse hover states when toggle button, because this is common for buttons.
Common states are Normal (what you see initially), Mouseover, Pressed and Disabled

Other states are related to checked, unchecked, or intermediate. Here, you can set different images for various states, etc. The mouse hover will always roll back to the public state.

If You must have this feature, you can create your own custom control for this, and handle the mouse hover animation according to the active state. This will require more code in the backend, because you need to redefine the button class of this object and insert various State testing to allow animation to be played for each state. I just don’t know if it’s worth the effort.

Leave a Comment

Your email address will not be published.