This is a migrated thread and some comments may be shown as answers.

PRISM/MVVM RadGridView and ContextMenu

6 Answers 483 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ralf
Top achievements
Rank 1
Ralf asked on 11 Feb 2011, 01:27 PM
Hi all,

in my current project i have some loosely coupled modules. Let´s say in module A we have a RadGridView with a region to extend the context menu.

        <telerik:RadGridView x:Name="radGridView" IsReadOnly="True" AutoGenerateColumns="False" ShowGroupPanel="false" RowIndicatorVisibility="Collapsed" ItemsSource="{Binding States}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
             
            <!-- CONTEXTMENU -->
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu x:Name="MachineStateContextMenu"  cal:RegionManager.RegionName="MachineStateContextMenu" Opened="RadContextMenu_Opened">
                    <telerik:RadMenuItem Header="Export" Click="RadMenuItem_Click">
                        <telerik:RadMenuItem.Icon>
                            <Image Source="/Joma.Workbench.Core;component/Images/page_excel.png" />
                        </telerik:RadMenuItem.Icon>
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem IsSeparator="True"/>
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
</telerik:RadGridView>

A other module (let`s call it B) extends region `MachineStateContextMenu` with one or more Items bound with commands.

<StackPanel>
    <telerik:RadMenuItem Header="Machinehistory" Command="{Binding MachineHistoryCommand}" />
</StackPanel>


How can i get the current slected row when `MachineHistoryCommand` is executed? My only idea at the moment is to fire an event via the eventaggregator to inform other modules about a changed selected row.

Are there any approaches that are more reasonable?

Greetings

Ralf

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 11 Feb 2011, 02:42 PM
Hello Ralf,

If the command is defined in your ViewModel and you want to be able to retrieve the selected item from that ViewModel, you may bind the SelectedItem property of the grid to a new exposed property in your ViewModel:

<telerik:RadGridView Name="playersGrid"
                   SelectedItem="{Binding MySelectedItem}"
                   ItemsSource="{Binding Players}" >
                            

In this case the MySelectedItem is your custom property and it is defined in the DataContext (probably your ViewModel).
In case you want to set the selected item on clicking on the RadContextMenu, you may take a look at this forum thread.
Let me know in case you need any further assistance or there is some misunderstandings according to your requirements.
 

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Ralf
Top achievements
Rank 1
answered on 11 Feb 2011, 03:24 PM
Hallo Maya, Thank you die your quick response! In my case there are two view models. The first on for the gridview in module A and the second is bound the usercontrol that extends the gridview context menu. the command bound to my menu item is part of module B As well as the model view for this control. When a user opens the context menu and calls the machine history, I want to know which one was choosen. This is essential because I want to create a new view to show the detailed data for a machine (the creation of this happens in module B). If this explanation is to confusing I will create a diagramto visualize it as soon as I'm back to the office. have a nice weekend. -ralf
0
Ralf
Top achievements
Rank 1
answered on 14 Feb 2011, 08:18 AM
Hello Maya,

i made a graphic to exemplify want i want to achieve.
0
Maya
Telerik team
answered on 17 Feb 2011, 08:51 AM
Hello Ralf,

Thank for the great diagram. I would gladly create a sample project based on it trying to resolve the issue you are working on. However, I would need one or two hints more. Does the Module B display the information for the selected item from the grid from Module A or maybe its RowDetails ? Does the Module B appears on clicking on the ContextMenu on the Module A or after selecting an item from the grid? Do you create a separate ContextMenu that you reuse (with the difference of a single item - MachineHistory) or you create two separate instances ? 
 

Kind regards,
Maya
the Telerik team
0
Ralf
Top achievements
Rank 1
answered on 17 Feb 2011, 09:08 AM
Hi Maya,

there is in this case only one information from a single column needed (it`s a production number).
With this one i gonna query a database to show detailed information within Module B.

After opening the context menu an clicking on the menu item, extended by Module B, the view
opens. The context menu providing the region is created by Module A (it`s serperate view) and uses a PRISM region
to enable a extension point. Module B extends this only with this:

<UserControl x:Class="Joma.Workbench.Modules.MaschinenAuswertung.MachineStatusContextMenuItems"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="75" d:DesignWidth="150">
    <StackPanel>
        <telerik:RadMenuItem Header="Machine Analysis" Command="{Binding MachineAnalysisCommand}" />
    </StackPanel>
</UserControl>

Maybe i find a couple of minutes to build a sample project with my structure.

Thanks for your help!
0
Maya
Telerik team
answered on 18 Feb 2011, 02:19 PM
Hello Ralf,

Firstly, thank you for the great cooperation and attitude. Unfortunately, I have to disappoint you in a way since we cannot suggest any easy solution that will not change the structure of your project. As the two modules are quite isolated, the data for the SelectedItem cannot be transfered. You may try to extend the modules and their ViewModel-s sot that they share the necessary information. The other approach may be to implement the RadTabControl instead. 

Regards,
Maya
the Telerik team
Tags
GridView
Asked by
Ralf
Top achievements
Rank 1
Answers by
Maya
Telerik team
Ralf
Top achievements
Rank 1
Share this question
or