Arlodotexe / strix-music

Combine any music sources into a single library. It's your music. Play it your way.
http://www.strixmusic.com
137 stars 4 forks source link

Use loose data coupling for events on templated items in ZuneAlbumCollection #124

Closed Arlodotexe closed 2 years ago

Arlodotexe commented 2 years ago

Background

In the Zune Desktop skin, we have a custom ZuneAlbumCollection that takes an IAlbumCollectionViewModel 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 a AlbumPlaybackTriggered event.

The ZuneAlbumCollection listens for this event on each album, and when fired, plays the clicked album in the context of the IAlbumCollectionViewModel.

image

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 the ZuneAlbumItem control directly from the templated ItemsControl using the index, then attaching to the AlbumPlaybackTriggered 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 the ZuneAlbumItem only when/if the control is loaded and the button is clicked.

Arlodotexe commented 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.

Arlodotexe commented 2 years ago

Bumping priority as this has caused a regression in the current app. Pretty easy to reproduce the play button not working.