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

ItemTap event

1 Answer 69 Views
ConversationView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Wayde
Top achievements
Rank 1
Wayde asked on 30 Jul 2012, 09:13 PM
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.

1 Answer, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 31 Jul 2012, 07:41 AM
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.

Tags
ConversationView
Asked by
Wayde
Top achievements
Rank 1
Answers by
Victor
Telerik team
Share this question
or