I am trying to bind a button to a viewmodel command using MVVM Light commands, and for some reason the command does not seem to be called. Usually I don't have problems with commands, but this one seems to ignore the binding.
Here is my code:
<ListBox.ItemTemplate> <DataTemplate> <StackPanel> <Button> <Interactivity:Interaction.Triggers> <Interactivity:EventTrigger EventName="Click"> <Command:EventToCommand Command="{Binding MyButtonClickAction}" /> </Interactivity:EventTrigger> </Interactivity:Interaction.Triggers> </Button> <StackPanel> <TextBlock Text="{Binding MyProperty}"/> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding MyOtherProperty}" /> </StackPanel> </StackPanel> </StackPanel> </DataTemplate> </ListBox.ItemTemplate>
This data template is in the list that is created after starting my application, and I wonder if this is a problem. My theory is that a view model is created and the constructor tries to establish a binding using the relay command, but since the list does not yet have elements, the binding does not complete correctly.
Linking with MyProperty and MyOtherProperty works fine.
Any suggestions on how I can get this to work?
source share