Easiest way to animate is using the Double Animation provided by WPF. It is much easier to use the Double Animation as there are only few statements needed and they are quite straight forward to implement. For e.g. Specifying the following parameters will let you start understand the animation easily
• From
• To
• RepeatBehavior
• Duration
After this setup, just calling the BeginAnimation method alongwith which property needs to be animated (in our case it is the right property) will start sliding horizontally.
Animation Setup
For horizontal marquee, we need two controls. One is the outer panel and the sliding label. For horizontal sliding or marquee we can either change the left property or right property using double animation object. For example we are going to try the right property.
If you want the sliding to be faster then reduce the duration. If you want the sliding to be slower, then duration has to be increased.
Animation in Listbox Items
Since we like to have the animation inside the listbox items, I made this label as the UserControl. So, we can either use inside the ListBox or can be used independently. Listbox Items bound to the data and values will be passed to listbox items while binding. We have to get the data and assign it to our Marquee control respectively.
DependencyPropertyChangedEvent
For transferring the values from the listbox to marque slider, we use the dependency property we created and named as MarqueeText. We need to register the property as the dependency property along with the event for property value changed. This event will be triggered whenever there is a change in the event.
We can retrieve the new value i.e the changed value from the event argument DependencyPropertyChangedEventArgs. There is a property named as e.NewValue.
• From
• To
• RepeatBehavior
• Duration
After this setup, just calling the BeginAnimation method alongwith which property needs to be animated (in our case it is the right property) will start sliding horizontally.
Animation Setup
For horizontal marquee, we need two controls. One is the outer panel and the sliding label. For horizontal sliding or marquee we can either change the left property or right property using double animation object. For example we are going to try the right property.
If you want the sliding to be faster then reduce the duration. If you want the sliding to be slower, then duration has to be increased.
Animation in Listbox Items
Since we like to have the animation inside the listbox items, I made this label as the UserControl. So, we can either use inside the ListBox or can be used independently. Listbox Items bound to the data and values will be passed to listbox items while binding. We have to get the data and assign it to our Marquee control respectively.
DependencyPropertyChangedEvent
For transferring the values from the listbox to marque slider, we use the dependency property we created and named as MarqueeText. We need to register the property as the dependency property along with the event for property value changed. This event will be triggered whenever there is a change in the event.
We can retrieve the new value i.e the changed value from the event argument DependencyPropertyChangedEventArgs. There is a property named as e.NewValue.
0 comments:
Post a Comment