MethodName not found when used in data template

Aug 3, 2011 at 7:38 PM

Tony, / All

I have an issue I am trying to resolve and I hope you can point me in the correct direction. Within a UserControl I have a Listbox that uses a DataTemplate to show results

<ListBox.ItemTemplate>
                <DataTemplate>                   
                        <Button Content="{Binding Path=buttonText}"
                                Height="{Binding Path=buttonHeight}"
                                Width="{Binding Path=buttonWidth}"
                                MinWidth="{Binding Path=buttonMinWidth}"
                                Margin="{Binding Path=buttonMargin}"
                                Background="Transparent"
                                BorderBrush="Transparent"
                                IsEnabled="{Binding Path=enabled}" >
                          <!-- Add reference to Microsoft.Expression.Interactions.dll, System.Windows.Interactivity.dll -->
                          <!-- Use mvvmxmlns snippet to add i and ei namespace prefixes -->
                          <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                              <ei:CallMethodAction
                                      TargetObject="{Binding}"
                                      MethodName="GetSearchResult"/>
                            </i:EventTrigger>
                          </i:Interaction.Triggers>
                        </Button>                   
                </DataTemplate>
            </ListBox.ItemTemplate>

WIthin the data template I have added the CallMethodAction. This method resides within my view model. The user control that this listbox resides in is loaded into my MainPage.xaml file which has within the header the DataContext Locator. When this button sits on the page outside of the datatemplate the method is called fine. However when I try to invoke the method from the data template button i recieve a error messsage that the method cannot be found.  Any suggestions as to what may be causing this?  Thanks in advance

Randy

Coordinator
Aug 13, 2011 at 11:21 PM

See my responses here.