Ticket T1282675
Visible to All Users

DXTabControl - select tab with right click

created a day ago

Hello,
I found this example in Ticket T281348 and tried to implement this feature into my application.
However the right click does not select the clicked tab.

Attached you find the modified example. Please advise how to get the clicked tab as the selected one.

Thanks
Wolfgang

Answers approved by DevExpress Support

created a day ago

Hello Wolfgang,

Thank you for the sample project.

At first glance, the following code in the event handler is sufficient to select a tab item:

C#
void AssociatedObject_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { var item = LayoutHelper.FindParentObject<DXTabItem>(e.OriginalSource as DependencyObject); if (item != null) AssociatedObject.SelectedContainer = item; }

Please let me know if this helps.

Regards,
Alexander

    Comments (3)

      Hello Alexander,
      thanks for the code. This does the trick.

      I already saw this code but did not want to use it because I found this:

      Moreover, LayoutHelper is not a part of our public API. Such classes can be changed or removed without warning or an out-of-the-box alternative in future updates. Therefore, we recommend against utilizing them in your code.

      in Ticket T1219394

      Regards
      Wolfgang

      Marc T (DevExpress Support) 17 hours ago

        Hello,

        Thank you for the update.

        At first glance, you can use LayoutTreeHelper.GetVisualParents instead to accomplish this task:

        C#
        void AssociatedObject_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { var item = LayoutTreeHelper.GetVisualParents(e.OriginalSource as DependencyObject) .OfType<DXTabItem>().FirstOrDefault(); if (item != null) AssociatedObject.SelectedContainer = item; }

        Please let me know if this helps.

        Regards,
        Marc

          Perfect thanks!

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.