V
V
Vyacheslav Zolotov2014-06-04 12:13:16
Windows
Vyacheslav Zolotov, 2014-06-04 12:13:16

Why doesn't Core:InvokeCommandAction work?

Hello. There is such a self-written control element:

<controls:ToggleList x:Name="toggleList" Grid.Row="4" x:Uid="PublishersToggleList" Items="{Binding PublishersList}">
                	<Interactivity:Interaction.Behaviors>
                        <Core:EventTriggerBehavior EventName="SelectedItemChanged">
                			<Core:InvokeCommandAction Command="{Binding PublishersChandgedCommand}" 
                                  CommandParameter="{Binding SelectedItem, ElementName=toggleList, Mode=OneWay}"/>
                		</Core:EventTriggerBehavior>
                	</Interactivity:Interaction.Behaviors>
                </controls:ToggleList>

Linked command code:
public RelayCommand<Publisher> PublishersChandgedCommand
        {
            get
            {
                return new RelayCommand<Publisher>((arg) =>
                {
                    if (arg != null)
                    {
                        SelectByPublisher(arg);
                    }
                });
            }

Why doesn't this approach work for a collection element of a different type? For example, when I do like this:
<controls:ToggleList x:Name="toggleList" Grid.Row="4" x:Uid="PublishersToggleList" Items="{Binding AutorList}">
              <Interactivity:Interaction.Behaviors>
                     <Core:EventTriggerBehavior EventName="SelectedItemChanged">
              		<Core:InvokeCommandAction Command="{Binding AutorListChandgedCommand}" 
                              CommandParameter="{Binding SelectedItem, ElementName=toggleList, Mode=OneWay}"/>
                     </Core:EventTriggerBehavior>
                </Interactivity:Interaction.Behaviors>
</controls:ToggleList>

The command binds, but when the SelectedItemChanged event occurs, a System.InvalidCastException is thrown inside the MVVM Light in the Execute method

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question