Strange behavior of button in TabItem HeaderTemplate

5 posts, 0 answers
  1. Stefan Babinec
    Stefan  Babinec avatar
    9 posts
    Member since:
    Mar 2010

    Posted 27 Apr 2010 Link to this post

    Hello.
    I'm using Q1 2010 for WPF.

    I have this following simple sample:
    <Window x:Class="sample.Window1" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:telNavigationControls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
        xmlns:telControlsControls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
        xmlns:sample="clr-namespace:sample" 
        Title="Sample Window" Height="300" Width="300"
         
        <Window.Resources> 
     
            <Style x:Key="TelerikTabItemContainerStyle" TargetType="{x:Type telNavigationControls:RadTabItem}"
                <Setter Property="HeaderTemplate"
                    <Setter.Value> 
                        <DataTemplate> 
                            <Button x:Name="closeButton" Content="Test Button" Height="25" sample:RoutedEventHelper.EnableRoutedClick="True"/> 
                        </DataTemplate> 
                    </Setter.Value> 
                </Setter> 
            </Style> 
     
        </Window.Resources> 
         
        <Grid> 
            <telNavigationControls:RadTabControl x:Name="mainTabControl" ItemContainerStyle="{StaticResource TelerikTabItemContainerStyle}" > 
     
                <telNavigationControls:RadTabItem > 
                    <telNavigationControls:RadTabItem.Content> 
                        <Button HorizontalAlignment="Center" VerticalAlignment="Center" Content="Test" IsDefault="True" /> 
                    </telNavigationControls:RadTabItem.Content> 
                </telNavigationControls:RadTabItem> 
     
            </telNavigationControls:RadTabControl> 
        </Grid> 
    </Window> 

    As you can see, there is one RadTabControl with one RadTabItem. I've modified RadTabItem header through ItemContainerStyle. There is only one button in HeaderTemplate. I've used RoutedEventHandler class for allowing the button's click events to be catched.
    Here is the code:
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Windows; 
    using System.Windows.Controls; 
     
    using Telerik.Windows; 
    using Telerik.Windows.Controls; 
     
    namespace sample 
        class RoutedEventHelper 
        { 
            // TAB CLOSE BUTTON EVENT 
            public static readonly RoutedEvent TabCloseButtonPressedEvent = EventManager.RegisterRoutedEvent( 
                "TabCloseButtonPressed", 
                RoutingStrategy.Bubble, 
                typeof(RoutedEventHandler), 
                typeof(RoutedEventHelper)); 
     
            // DEPENDENCY PROPERTY FOR TAB ITEM HEADER BUTTON 
            public static readonly DependencyProperty EnableRoutedClickProperty = DependencyProperty.RegisterAttached( 
               "EnableRoutedClick", 
               typeof(bool), 
               typeof(RoutedEventHelper), 
               new PropertyMetadata(OnEnableRoutedClickChanged)); 
     
            // Add an attached property 
            public static bool GetEnableRoutedClick(DependencyObject obj) 
            { 
                return (bool)obj.GetValue(EnableRoutedClickProperty); 
            } 
     
            public static void SetEnableRoutedClick(DependencyObject obj, bool value) 
            { 
                obj.SetValue(EnableRoutedClickProperty, value); 
            } 
     
            // TAB EVENT HANDLER 
            private static void OnEnableRoutedClickChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) 
            { 
                var button = sender as Button; 
     
                if (button != null) 
                    button.Click += CloseButton_Click; 
            } 
     
            private static void CloseButton_Click(object sender, RoutedEventArgs e) 
            { 
                var button = sender as Button; 
                if (button == null) return; 
     
                button.RaiseEvent(new RoutedEventArgs(TabCloseButtonPressedEvent, button)); 
            } 
        } 
     

    Everything works fine with one exception. If I put another Button as RadTabItem Content (as you can see in the above xaml example) and I set property of this button "IsDefault = true", the click events from the first button in RadTabItem header are not fired.
    Is this behavior correct ?

    I have also second question:
    Imagine almost the same situation as in the previous example. I've RadTabItem with modified HeaderTemplate with one button in it. I've no buttons in the RadTabItem Content, so when I click on Button in my RadTabItem header, the click event is fired correctly. 
    Let's continue. Now I've got for example two RadTabItems (with the same HeaderTemplate) in one RadTabControl. The first RadTabItem is selected, the second one not. And now here it comes. When I click on the button (button in RadTabItem header) in the RadTabItem which is NOT selected, the event is not fired, only this specified RadTabItem becomes selected. So the click events are fired only when the RadTabItem is Selected.

    The following behavior would be best for me: When I click on the button in header of arbitrary RadTabItem (selected or not) the click event of the button will be fired but the selection of the RadTabItems will NOT changed.

    Is this scenario possible ? Or it would be great if at least the event of the buttons will be fired no matter the RadTabItem is selected or not.

    Thank you a lot.

    Stefan.



  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 30 Apr 2010 Link to this post

    Hi Stefan ,

    Thank you for your feedback. After some debugging, I came to the conclusion that this behavior is not normal and there seems to be an issue in our TabControl. I've logged the issue in our PITS under the name "TabControl: Cannot click button in the header if button in the content is marked as IsDefault". The issue will be available for tracking tomorrow the latest. We will try to fix it as soon as possible, but I cannot bind to a specific date. Meanwhile, if it is possible, you can skip the usage of IsDefault. Another partial workaround is to set Focusable="False" to the button that is marked with IsDefault="True".
    I believe the second questions is closely related to this issue i.e. if this issue does not exist, you will be able to successfully click the NOT selected tab item.
    Let me know what's your opinion on the topic. I've also added 1000 Telerik points to your account.

    Sincerely yours,
    Kiril Stanoev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Stefan Babinec
    Stefan  Babinec avatar
    9 posts
    Member since:
    Mar 2010

    Posted 02 May 2010 Link to this post

    Hi Kiril.

    Thanks for the answer.

    To the second part of my question in the previous post.
    Yes, it is somehow related to the first issue. When I set the "Focusable" property of buttons in the RadTabItem.Content to "false", than the events from buttons in Header are fired correctly no matter if the tab is selected or not.
    But it works in my case only in this simple case. I've been experimenting with the following xaml:
     <Grid> 
            <telNavigationControls:RadTabControl ItemContainerStyle="{StaticResource TelerikTabItemContainerStyle}" > 
                <!--FIRST ITEM--> 
                <telNavigationControls:RadTabItem > 
     
                    <telNavigationControls:RadTabItem.Content> 
                        <telDockingControls:RadDocking Focusable="False" > 
                            <telDockingControls:RadSplitContainer Focusable="False"
                                <telDockingControls:RadPaneGroup Focusable="False"
                                    <telDockingControls:RadPane Focusable="False" > 
                                        <Button Content="Test Content Button" Focusable="False"/> 
                                    </telDockingControls:RadPane> 
                                </telDockingControls:RadPaneGroup> 
                            </telDockingControls:RadSplitContainer> 
                        </telDockingControls:RadDocking> 
                    </telNavigationControls:RadTabItem.Content> 
     
                </telNavigationControls:RadTabItem> 
     
                <!--SECOND ITEM--> 
                <telNavigationControls:RadTabItem > 
     
                    <telNavigationControls:RadTabItem.Content> 
                        <telDockingControls:RadDocking Focusable="False" > 
                            <telDockingControls:RadSplitContainer Focusable="False"
                                <telDockingControls:RadPaneGroup Focusable="False"
                                    <telDockingControls:RadPane Focusable="False" > 
                                        <Button Content="Test Content Button" Focusable="False"/> 
                                    </telDockingControls:RadPane> 
                                </telDockingControls:RadPaneGroup> 
                            </telDockingControls:RadSplitContainer> 
                        </telDockingControls:RadDocking> 
                    </telNavigationControls:RadTabItem.Content> 
     
                </telNavigationControls:RadTabItem> 
     
            </telNavigationControls:RadTabControl> 
     
        </Grid> 

    The rest of the xaml is the same as in my previous post. The only difference is that I put RadDocking Control as a content of RadTabItem. I've tried to set "Focusable = false" property to everything in RadTabItem.Content and in this case the events from Header buttons are not fired correctly.

    As I said before, when I click on the Header Button in RadTabItem which is not selected, only the RadTabItem is selected and the event is not fired.

    Thanks a lot.

    Stefan.

  5. Stefan Babinec
    Stefan  Babinec avatar
    9 posts
    Member since:
    Mar 2010

    Posted 05 May 2010 Link to this post

    Hi Kiril.

    I'm also not able to find this case in PITS.
    Is it there ?

    Thanks a lot.

    S.

    ******
    Sorry, I've found it already. I was searching for it in 2010 Q1 SP+
    My mistake :-)
    S.
  6. Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 05 May 2010 Link to this post

    Hi Stefan,

    You can track the issue following this link.

    Greetings,
    Ivan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
UI for WPF is Visual Studio 2017 Ready