RadComboBox and CallMethodAction

2 posts, 0 answers
  1. Poubelle
    Poubelle avatar
    7 posts
    Member since:
    Mar 2011

    Posted 27 Feb 2012 Link to this post

    Hi,

    I’m developing a Gridview application in Silverlight, where i’ve got inside a CellEditTemplate with a RadComboBox. I need to call specific method in my ViewModel when i click in my RadComboBox. How can i redefine again my context to fin the method, because with my code (below), I’ve the error that say my RadGridView ItemSource do not contains my method.
    Anyone can help me?
    Thanks
    Regards

    <telerik:RadGridView x:Name="myPrdContent"
                            ItemsSource="{Binding ResultSearch2}"
                            AutoGenerateColumns="False"
                            ShowGroupPanel="False"
                            IsFilteringAllowed="False">
        <telerik:RadGridView.Columns>
     
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Age}"
                                        Width="*"
                                        MinWidth="200"
                                        >
                <telerik:GridViewDataColumn.Header>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <TextBlock Margin="2"
                                    Text="Age"
                                    Grid.Row="0" />
                    </Grid>
                </telerik:GridViewDataColumn.Header>
                <telerik:GridViewDataColumn.CellEditTemplate>
                    <DataTemplate>
                        <telerik:RadComboBox x:Name="RadComboBox1" Margin="0 10 0 10" VerticalAlignment="Center"
                                CanAutocompleteSelectItems="False"
                                CanKeyboardNavigationSelectItems="False"
                                IsEditable="True"
                                IsReadOnly="False"
                                OpenDropDownOnFocus="False"
                                IsFilteringEnabled="False"
                                TextSearchMode="Contains"
                                IsDropDownOpen="False"
                                EmptyText="...::Empty::.."
                                                    SelectedValue="{Binding SearchLibelle, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                            Text="{Binding SearchLibelle, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                            Width="300" DataContext="{Binding}" >
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="DropDownOpened">
                                    <ei:CallMethodAction MethodName="Search" TargetObject="{Binding DataContext, ElementName=RadComboBox1}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </telerik:RadComboBox>
                    </DataTemplate>
                </telerik:GridViewDataColumn.CellEditTemplate>
            </telerik:GridViewDataColumn>
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>
  2. Poubelle
    Poubelle avatar
    7 posts
    Member since:
    Mar 2011

    Posted 27 Feb 2012 Link to this post

    Hi,

    I’ve found a solution.
    1) Add my ViewModel as ressouce in my window
    <Window.Resources>
       <AppViewModel:MainWindowsViewModel x:Key="MyViewModel"/>
    </Window.Resources>

    2) Change the DataContext from the RadComboBox
    DataContext="{Binding source={StaticResource MyViewModel}}"

    Thanks all.
  3. DevCraft banner
Back to Top