Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
460
How to determine item clicked in the content area
posted

Hi,

 

i have a databound collection much like the example code that shows how to bind to the header and then puts a listbox in the content area.  My question is how do you determine whoch item is clicked on.  I have a context menu and when i try to determine the item selected I can only get to the group selected.   the xamOutlookBar1.SelectedGroup.Content returns my collection.  How do you figure out which one in that group is the one clicked on?

 

Thanks in advance

Parents
No Data
Reply
  • 2677
    Suggested Answer
    posted

    Hello,

    The easiest way to get this information is to handle the SelectionChanged event of the ListBox within the DataTemplate.  Inside of that event, you can obtain the selected Item text and store it in the XamOutlookBar1.SelectedGroup.Tag property.  Then, when you are opening your tag property, you can look in the SelectedGroup.Tag to find the selected value from the ListBox.  Here is some sample code of what I have done.  It works directly with the sample that comes with the product. 

    I handled the SelectionChanged event in the DataTemplate:

    <ListBox ItemsSource="{Binding}" SelectionChanged="ListBox_SelectionChanged" x:Name="ListBox1">

    Then, in the event, I did the following:

    private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                ListBox lb = sender as ListBox;           
                for(int i=0; i < lb.SelectedItems.Count; i++)
                {              
                    System.Xml.XmlNode node = lb.SelectedItems[i] as System.Xml.XmlNode;
                    this.XamOutlookBar1.SelectedGroup.Tag = node.Attributes["text"].Value.ToString();
                }         
            }

    Now the Tag property has the values that I want.  I hope this helps.  If there is anything else I can do for you, please let me know

     

Children
No Data