InteractiveViewModel and PlayerFramework 2.0

Jun 10, 2014 at 1:35 PM
Edited Jun 10, 2014 at 1:47 PM
Greetings !

When I was using PlayerFramework 1.8.2.2, I extended InteractiveViewModel by my own class, let's call it TestIVM.

I was using that to display the title and a back command on the top of the screen.

Now however, I have the following issue :

1) If I do not override the player's InteractiveViewModel, everything works perfectly.
2) If I do override it, I get the following error on 4-5 buttons (that I customized in the ControlTemplate of the ControlPanel) :
Error: Converter failed to convert value of type 'Test.ViewModels.TestIVM, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' to type 'IInteractiveViewModel'; BindingExpression: Path='ViewModel' DataItem='Microsoft.PlayerFramework.ControlPanel'; target element is 'Microsoft.PlayerFramework.PlayPauseButtonBehavior' (Name='null'); target property is 'ViewModel' (type 'IInteractiveViewModel').

This is how I place a Play/Pause button in the ControlTemplate :
<Button x:Name="PlayPauseButton" Style="{TemplateBinding TransportBarButtonStyle}" Width="30" Height="30" Visibility="{Binding IsPlayPauseButtonVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}" Margin="30,0,8,0">
                            <local:MediaControls.Behavior>
                               <local:PlayPauseButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}" />
                            </local:MediaControls.Behavior>
                        </Button>
This is the line that conflicts :
<local:PlayPauseButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}"/>
This template has been obtained from EntertainmentTheme.xaml , and modified afterwards to remove some buttons.

Is there something I should be doing with the default InteractiveViewModel of the player??

Please advise.

Thank you in advance !
Coordinator
Jun 10, 2014 at 2:49 PM
You should be able to fix this by adding a dummy instance of your custom ivm to your app.xaml. This forces the compiler to generate xaml typeinfo for the class which allows it to participate in binding.

Note: In the future please post Win8 & WP questions to playerframework.CodePlex.com. Thanks!
Marked as answer by stefangavrilas on 6/10/2014 at 11:29 AM
Jun 10, 2014 at 6:30 PM
Thank you !

In the past this wasn't an issue, and the documentation hasn't been updated to specify this :)

Thank you however for your quick reply.
Jul 24, 2014 at 1:06 AM
I've seen this trick (the dummy instance) be used to avoid some "optimization" that doesn't load resourcedictionaries which are nested some levels deep or something like that. So maybe it has to do with where you define your resources
Sep 12, 2014 at 6:19 PM
Edited Sep 12, 2014 at 6:20 PM
In fact, it is enough to simply reference your custom ivm in app.xaml, for instance:
<Style x:Key="DummyStyle" TargetType="local:YourCustomInteractiveViewModel" />
This avoids creating an instance, and also the need to have a default constructor.