Closed Arlodotexe closed 2 years ago
@amaid I've assigned you to this issue to work on. The loose data coupling using custom ViewModels and behaviors is a technique I'd like to make sure you can do.
Bumping priority as this has caused a regression in the current app. Pretty easy to reproduce the play button not working.
Background
In the Zune Desktop skin, we have a custom
ZuneAlbumCollection
that takes anIAlbumCollectionViewModel
and displays them to the user.There's also a button on each album that play the album when clicked. This button is on the
ZuneAlbumItem
, and when clicked, the control emits aAlbumPlaybackTriggered
event.The
ZuneAlbumCollection
listens for this event on each album, and when fired, plays the clicked album in the context of theIAlbumCollectionViewModel
.The problem
We're listening for the
AlbumPlaybackTriggered
event in a way that doesn't play nicely with the UI framework.When the control is loaded, and again as needed when the
Albums
collection is changed, we're getting theZuneAlbumItem
control directly from the templated ItemsControl using the index, then attaching to theAlbumPlaybackTriggered
event.This results in the following issues:
The solution
The proposed solution uses loose data coupling by wrapping each templated model in a custom ViewModel and wiring the events together.
This approach means events can be set up for every item in the
ZuneAlbumCollection
, and invoked by theZuneAlbumItem
only when/if the control is loaded and the button is clicked.