ItemTap event

2 posts, 0 answers
  1. Wayde
    Wayde avatar
    17 posts
    Member since:
    Jun 2012

    Posted 30 Jul 2012 Link to this post

    Is there any way of getting the item that has been tapped? I need to find out which conversation item a user has selected, but I cannot find a way to get this to work.

    Alternatively, is there a way to get a HyperLinkButton to fire an event from within the IncomingMessageTemplate or OutgoingMessageTemplate? I have tried this from within the DataTemplate, but my events do not fire when clicked on. For instance, if a user were to send a link in a message, I want to be able to click this.
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 31 Jul 2012 Link to this post

    Hi Wayde,

    Thanks for writing.
    Currently, there are two very easy ways to get to the selected item:
    1. Manually search for the selected item on tap:

    private void OnConversationViewTap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        RadDataBoundListBoxItem listBoxItem = ElementTreeHelper.FindVisualDescendant<RadDataBoundListBoxItem>(sender as DependencyObject, (child) =>
        {
            RadDataBoundListBoxItem item = child as RadDataBoundListBoxItem;
            if (item == null)
            {
                return false;
            }
     
            Rect layoutSlot = new Rect(new Point(), item.RenderSize);
            Point tapLocation = e.GetPosition(item);
     
            return layoutSlot.Contains(tapLocation);
        });
     
        if (listBoxItem == null)
        {
            return;
        }
     
        object message = listBoxItem.Content;
    }

    2. Extend RadConversationView, expose a SelectedItem property and then use the new conversation view.
    public class CustomConversationView : RadConversationView
    {
        private RadDataBoundListBox listBox;
     
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.listBox = this.GetTemplatePart<RadDataBoundListBox>("PART_ListBox");
        }
     
        public object SelectedItem
        {
            get
            {
                if (this.listBox == null)
                {
                    return null;
                }
     
                return this.listBox.SelectedItem;
            }
     
            set
            {
                if (this.listBox == null)
                {
                    return;
                }
     
                this.listBox.SelectedItem = value;
            }
        }
    }

    You can get the HyperLinkButton event by using commands. Every button has a Command property that you can set to your own command in which you can whatever is necessary.

    Thanks for the feedback, we'll consider exposing an ItemTapped event or ItemSelected in a future release.
    Please write again if you need further assistance.

    Regards,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top