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
165
Converting UIElement to UltraListViewItem
posted

Hi,

I have an UltraListView that is populated with several items. What I am trying to do is have an action happen to the UltraListViewItem when a mouse enters and leaves the item, using the MouseEnterElement and MouseLeaveElement events. Unfortunately I don't know how to get the UltraViewListItem from the UIElementEventArgs that is passed into those methods. This is what I have tried but does not work:

 

private void Browser_MouseEnterElement( object sender, Infragistics.Win.UIElementEventArgs e )
        {
            UltraListViewItem itemEnter = e.Element as UltraListViewItem;
            if( itemEnter != null )
            {
                //do stuff with item

           }
        }

        private void Browser_MouseLeaveElement( object sender, Infragistics.Win.UIElementEventArgs e )
        {
            UltraListViewItem itemLeave = e.Element as UltraListViewItem;
            if( itemLeave != null )
            {
                //do stuff with item

           }
        }

Parents
No Data
Reply
  • 69832
    Verified Answer
    Offline posted

    The UltraListViewItemUIElement class encapsulates the item's physical representation on the screen; it derives (as all such Infragistics classes do) from UIElement. When handling MouseEnterElement/MouseLeaveElement, cast e.Element to the expected type, then check for a non null return. Note that in this case, the element class exposes a property that references the underlying object, but for UIElement classes that don't, you can oftentimes use the UIElement.GetContext method to get that reference.

    Example:
    private void Browser_MouseEnterElement(object sender, UIElementEventArgs e)
    {
        UltraListViewItemUIElement itemElement = e.Element as UltraListViewItemUIElement;
        UltraListViewItem item = itemElement != null ? itemElement.Item : null;
        if ( item != null )
            System.Diagnostics.Debug.WriteLine( item.Text );
    }

Children
No Data