get selected item(object ) upon clicking a tileview item

5 posts, 1 answers
  1. Harinath Reddy
    Harinath Reddy avatar
    4 posts
    Member since:
    Nov 2010

    Posted 23 May 2011 Link to this post

    hi team telerik,


    I got a situation here.i'm using the tile view F1 race example of yours.

    i am getting a collection of patient from the database and binding it to the radtileview item source.

    i'm interested in getting the selected item upon right  clicking(context menu) on the tile view(which should be the patient object)
    same as getting selected item in rad grid view.how can i do that.

    please find an image which might help you in figuring out what i want.

    hope you reply at the earliest.


  2. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 25 May 2011 Link to this post

    Hello Harinath Reddy,
    When you click on a context menu item you can get the selected tileview item with the GetClickedElement<RadTileViewItem>() method of the RadContextMenu. For further references could you please examine the attached project and if you need more help feel free to ask.

    All the best,
    Zarko
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Harinath Reddy
    Harinath Reddy avatar
    4 posts
    Member since:
    Nov 2010

    Posted 30 May 2011 Link to this post

     Hello Zarko,

    Thanks for your assistance.
    The solution you attached could not address  my the problem 
    i am attaching the screen shot once again.
    I am using lauret bugnion MVVM light framework.


    here is my view:
    <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Telerik.Windows.Examples.TileView.Integration.Example"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls"
                 Width="500" Height="500" >
    <UserControl.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="../../Common/DynamicPositionTemplates.xaml" />
    </ResourceDictionary.MergedDictionaries>


    <DataTemplate x:Key="TeamTemplate"

    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding ID}" VerticalAlignment="Center" />
    <TextBlock Text="{Binding Name}" Width="auto" VerticalAlignment="Center" />

    <TextBlock Text="{Binding Address}" Width="auto" VerticalAlignment="Center" />
                        
                    </StackPanel>
    </DataTemplate>
            </ResourceDictionary>
    </UserControl.Resources>


        <Grid>
            <Border Background="#e0dfdd" CornerRadius="7">
    <Grid Margin="8">
                <StackPanel Orientation="Vertical">
                    <Grid Margin="10 0 0 0">
                      
                    </Grid>
                   
                    <Grid Margin="10 0 0 0">
       <telerik:RadTileView Margin="0 16 0 0" ItemsSource="{Binding Customers}" MaximizeMode="Zero"
       ItemTemplate="{StaticResource TeamTemplate}" MaxColumns="1"
       ItemContainerStyle="{StaticResource RadTileViewItemStyle}" />
                            <telerik:RadContextMenu.ContextMenu>
                                <telerik:RadContextMenu x:Name="ContextMenu">


                                    <telerik:RadMenuItem Header="Send To Lab"
                                                         Command="{Binding SendToLabCmd}" 
                                                         CommandParameter=""/>   ---------------------->I could not figure out What to send as command parameter
                                    <telerik:RadMenuItem Header="Send To Consultation" />


                                </telerik:RadContextMenu>
                            </telerik:RadContextMenu.ContextMenu>


                        </Grid>
                </StackPanel>
            </Grid>
           
        </Border>


            
        </Grid>


    </UserControl>

    And this is my View model:

    using System;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Windows.Threading;
    using System.Linq;
    using Telerik.Windows.Controls;
    using System.Collections.Generic;
    using GalaSoft.MvvmLight.Command;
    using System.Windows;


    namespace Telerik.Windows.Examples.TileView.Common.ViewModels
    {
        public partial class MainViewModel : ViewModelBase
        {




            public MainViewModel()
            {
                SendToLabCmd = new RelayCommand(new System.Action(SendToLabCmdExecute));
            }


            public RelayCommand SendToLabCmd { get; set; }
           
            public void SendToLabCmdExecute()
            {
                MessageBox.Show("Cmd testing");
            }


            public List<Customer> Customers
            {
                get
                {
                    Customer c = new Customer();
                    return c.allcustomers();
                }


            }
        }
    }
    public class Customer
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }


        public List<Customer> allcustomers()
        {
            List<Customer> allcust = new List<Customer>();


            Customer c1 = new Customer { ID = 1, Name = "John", Address = "Newyork" };
            Customer c2 = new Customer { ID = 2, Name = "kiran", Address = "chicago" };
            Customer c3 = new Customer { ID = 3, Name = "Max", Address = "Newyork" };
            Customer c4 = new Customer { ID = 4, Name = "raj", Address = "Newyork" };
            Customer c5 = new Customer { ID = 5, Name = "mary", Address = "Newyork" };
            allcust.Add(c1);
            allcust.Add(c2);
            allcust.Add(c3);
            allcust.Add(c4);
            allcust.Add(c5);
            return allcust;
        }
    }







    All i want is when i left click on the tile view and select "Send to lab" rad menu item,I need to get the  customer object(displayed on the rad tile) and access it in my view model.how can i do that..I could not figure out what to send as command parameter. 

    If you can post a sample that will be of much help.
    I hope this will help you in understanding my requirement.
    Hope you reply at the earliest..


  5. Answer
    Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 31 May 2011 Link to this post

    Hi Harinath Reddy,
    You should pass the clicked customer as a Command Parameter, but to do this you'll have to handle the Opened event of the RadContextMenu and get it with GetClickedElement<RadTileViewItem>() method. You can't go around this event handler in the code behind because in some point you'll have get the visually clicked element and this can't be done in the ViewModel.
    For further references could you please examine the attached project and if you have more questions feel free to ask.

    Regards,
    Zarko
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Harinath Reddy
    Harinath Reddy avatar
    4 posts
    Member since:
    Nov 2010

    Posted 01 Jun 2011 Link to this post

     Hello Zarko,

    Thanks for your assistance.
    The solution you attached helped me alot to get my requirement.

    once again Thanks alot.
Back to Top
DevCraft banner