Animate ListBoxItem on Load
I ha开发者_运维知识库ve a list where I want to animate (blink) the last selected item (obtained from state) on page load. It is a databound listbox. How do we do it traditionally? How do we do it in MVVM?
The way I would go about it is to have a ViewModel Property that oscillates between 0 and 1 at increments of 0.01 ~ 0.05, depending on how slow/fast you want the transition, and bind that property to the opacity in the SelectedItemTemplate.
To attain "oscillation", you can use something temporal. (DateTime.Now.Second / 60) during "even" minutes and (60 - DateTime.Now.Second) / 60 during "odd" minutes
No extra infrastructure or coding needed. Since our measuring stick is time you can adjust accordingly for the appropriate frequency and speed.
If your viewmodel that the list is bound to contains the flag "WasLastSelected", or whatever, then you could encapsultate/subclass the UI controls in your datatemplate and fire the onload event which can check the DataContext for that property and fire an animation (also defined in the user control) if the flag is true.
Does that make sense?
精彩评论