Telerik RadGridView custom template don't call method in viewmodel

Nov 22, 2011 at 12:43 PM

Hello,

I've developed a RadGridView as follow :

 <telerik:RadGridView Grid.Row="1" ItemsSource="{Binding SecuritiesNoteResult}" AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
             <!-- some other grid-->
                <telerik:GridViewDataColumn UniqueName="FileOpen" Header="Visualizza" x:name="test">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <Button HorizontalContentAlignment="Center" Click="Button_Click" >
                                <Button.Content>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Source="/DOME;component/Media/pdfDocument.png" Height="20" Width="20" />

                                    </StackPanel>
                                </Button.Content>
                            </Button>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>       
        </telerik:RadGridView>

and in the viewmodel I've :

        public void test()
        {
            _windowManager.ShowWindow(new ReportViewModel(_repository));
        }

The event is not fired... I've tried both to put x:name on the Button and in the GridViewDataColumn... I think I'm missing something really simple... any suggestion?

Thanks

Nov 22, 2011 at 3:01 PM

First unless you have created a convention for the control it won't be bound.  How did you try to use the button ?  I see a click event handler and that isn't necessary with CM.  Have you tried cal:Message.Attach="test" in your button?

 

Morgan.

Nov 22, 2011 at 3:14 PM

Hello Morgan,

not yet... I've set a button click just for test, since if I put a Button outside the radgridview it works... But the convention should be defined where? can you provide me a sample please?

Thanks

Nov 22, 2011 at 3:36 PM

Conventions are defined in the Configure() method I usually follow the same practice that is put forth in the examples and call a void method AddConventions();

there is a sample for the Conventions, I wouldn't even know where to begin with the GridView from them to create a convention for binding, but can you look at the Bootstrapper for the sample projects you will see examples for Pivot/Panorama for the WP7 samples.

Doing a click event would work but it won't call Test unless you get an instance of the viewmodel off the datacontext to expose the Test method.

Nov 22, 2011 at 3:38 PM

Test was just for testing.... in my viewmodel there was a public void Test() .... wich work if I use a Button outside the radgridview...

Thanks

Nov 22, 2011 at 4:30 PM

that is why I suggested cal:Message.Attach="Test" it should pick that up.  Then again it might cause of the datatemplate.

Nov 23, 2011 at 7:55 AM

hello,

using the cal:Message.Attach worked but I needed to have the Item of the selected row so I used the

<Button cal:Message.Attach="RemoveName($datacontext)" ... />

as defined here
http://caliburn.codeplex.com/discussions/246686

Thanks