Radpane GotFocus

12 posts, 1 answers
  1. Jonam
    Jonam avatar
    36 posts
    Member since:
    Jul 2010

    Posted 15 Aug 2010 Link to this post

    I want to know which radpane has got the focus. I catch the event GotFocus. This work perfect when the radpanes are tabbed. If i dock the radpane to the left, right or floating then suddenly the window i moved doesn't fire the GotFocus event. This is my code.

    <telerik:RadDocking Grid.Row="1" HasDocumentHost="True" HorizontalAlignment="Stretch" Name="radDocking1" VerticalAlignment="Stretch">
        <telerik:RadDocking.DocumentHost>
            <telerik:RadSplitContainer VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
                <telerik:RadPaneGroup x:Name="radPaneGroup" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                    <telerik:RadPane x:Name="radPaneAccountlevel6" Header="Hoofdposten" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" GotFocus="radPaneAccountlevel6_GotFocus">
                        <my:AccountLevel5TotalView Grid.Row="1" Name="accountLevel5TotalView1" />
                    </telerik:RadPane>
                    <telerik:RadPane x:Name="radPaneAccountlevel5" Header="Subposten" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" GotFocus="radPaneAccountlevel5_GotFocus">
                        <TextBlock TextWrapping="Wrap" Text=""></TextBlock>
                    </telerik:RadPane>
                    <telerik:RadPane x:Name="radPaneAccountlevel4" Header="Accountlevel4" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" GotFocus="radPaneAccountlevel4_GotFocus">
                        <TextBlock TextWrapping="Wrap" Text=""></TextBlock>
                    </telerik:RadPane>
                    <telerik:RadPane x:Name="radPaneAccountlevel3" Header="Accountlevel3" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" GotFocus="radPaneAccountlevel3_GotFocus">
                        <TextBlock TextWrapping="Wrap" Text=""></TextBlock>
                    </telerik:RadPane>
                    <telerik:RadPane x:Name="radPaneAccountlevel2" Header="Accountlevel2" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" GotFocus="radPaneAccountlevel2_GotFocus">
                        <TextBlock TextWrapping="Wrap" Text=""></TextBlock>
                    </telerik:RadPane>
                    <telerik:RadPane x:Name="radPaneAccountlevel1" Header="Accountlevel1" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" GotFocus="radPaneAccountlevel1_GotFocus">
                        <TextBlock TextWrapping="Wrap" Text=""></TextBlock>
                          
                    </telerik:RadPane>
                    <telerik:RadPane x:Name="radPaneContract" Header="Opdrachten" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" GotFocus="radPaneContract_GotFocus">
                        <TextBlock TextWrapping="Wrap" Text=""></TextBlock>
                    </telerik:RadPane>
                    <telerik:RadPane x:Name="radPaneBill" Header="Facturen" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" GotFocus="radPaneBill_GotFocus">
                        <TextBlock TextWrapping="Wrap" Text=""></TextBlock>
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
        </telerik:RadDocking.DocumentHost>
    </telerik:RadDocking>

    Is this their a work around to this problem?

    kind regards,

    Jonam
  2. George
    Admin
    George avatar
    1332 posts

    Posted 18 Aug 2010 Link to this post

    Hello Jonam,

    Thank you for contacting us.

    When you dock a pane outside the initial RadPaneGroup where it is generated, this pane is placed in a new created RadSplitContainer and a new RadPaneGroup. If you make it floating, a ToolWindow is generated and the content for this RadPane plus a new RadPaneGroup and RadSplitContainer are placed in this ToolWindow. This is how RadDocking works. In this circumstances you lose GotFocus event handler. If you want to get focused the content in RadPane when it goes floating, you could handle GotFocus event of the ToolWindow.

    Could you give us some more details what is your scenario and why do you need to handle GotFocus event for each RadPane

    I hope this information helps. I will be glad to assist you further.

    Best wishes,
    George
    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. DevCraft banner
  4. Jonam
    Jonam avatar
    36 posts
    Member since:
    Jul 2010

    Posted 19 Aug 2010 Link to this post

    Hello George,

    thank you for responding and explaning the event and process cycle of docking. The scenario in which i need to handle GotFocus event for each RadPane is the following.

    I want to know which RadPane is last selected so i can display a context senstive menu in the ribbonbar. But if the got focus event suddenly doesn't respond any more because it is in a toolwindow then i context menu doesn't matches the active window.

    Do you know the solution to this problem?

    kind regards,

    Jonam
  5. Jonam
    Jonam avatar
    36 posts
    Member since:
    Jul 2010

    Posted 19 Aug 2010 Link to this post

    Got a part of  the solution. Catch the LayoutChangeStarted off the radDocking and find the active radpane with the following statements. But after i click on a tabbed control and then the toolwindow i get no event. How do i get a reference to the toolwindow?

     

     

     

     

     

    List<RadPane> list = radDocking1.Panes.ToList();
    list = list.Where(x => x.IsSelected && x.IsFocused ).ToList();
  6. Answer
    George
    Admin
    George avatar
    1332 posts

    Posted 19 Aug 2010 Link to this post

    Hello Jonam,

    That's a right approach to get the latest selected RadPane.

    You need to handle GotFocus event for the ToolWindow when a pane goes floating. You could do this using PaneStateChange event. It fires when a RadPane changes its state. For example:

    private void RadDocking_PaneStateChange(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                RadPane pane = e.Source as RadPane;
                if (pane != null && pane.IsFloating)
                {
                    ToolWindow toolWindow = pane.ParentOfType<ToolWindow>();
                    if (toolWindow == null)
                    {
                        toolWindow = (((pane.Parent as RadPaneGroup).Parent as RadSplitContainer).Parent) as ToolWindow;
                        if (toolWindow != null)
                        {
                            toolWindow.GotFocus += new RoutedEventHandler(toolWindow_GotFocus);
                        }
                    }
                    else
                    {
                        toolWindow.GotFocus += new RoutedEventHandler(toolWindow_GotFocus);
                    }
                }
            }
     
    There is a bug in the framework when you make RadPane floating via the ContextMenu - ParentOfType<ToolWindow> returns null in these circumstances. That's why you could get the ToolWindow using Parent property. When you found it, you could handle GotFocus event and it will fires everything when this ToolWindow gets focused. I suggest you to detach GotFocus event handler when the ToolWindow is closing.

    I hope this helps! I will be glad to assist you further.

    Kind regards,
    George
    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
  7. Jonam
    Jonam avatar
    36 posts
    Member since:
    Jul 2010

    Posted 20 Aug 2010 Link to this post

    Thank you george this works almost 100%. I have now only a minor issue. What if the user drags a pane into a toolwindow. Next they drag another pane to dock into this toolwindow? I tried the code below but this doesn't work. How to realize this final step? p.s.  if i don't detach the gotFocus event handler isn't this disposed in the garbage collection?


    void toolWindow_GotFocus(object sender, RoutedEventArgs e)
    {
        ToolWindow window = (ToolWindow)sender;
          
        RadSplitContainer container = (RadSplitContainer)window.Content;
        if (container != null)
        {
            foreach (RadPaneGroup group in container.Items)
            {
                foreach (RadPane pane in group.Items)
                {
                    if (pane.IsSelected)
                        ActiveWindow = GetWindowConstantFromPaneName(pane.Name);
                }
            }
        }
        groupRefresh.Header = ActiveWindow;
    }
  8. George
    Admin
    George avatar
    1332 posts

    Posted 25 Aug 2010 Link to this post

    Hi Jonam,

    Could you please describe the problem in details. What do you mean by saying "doesn't work"?
    GC collects only objects in the managed heap that are no longer being used by the application. I suggest you to detach the event handler manually.
     
    Looking forward to your reply.

    Sincerely yours,
    George
    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
  9. kyle
    kyle avatar
    21 posts
    Member since:
    Sep 2010

    Posted 10 Nov 2010 Link to this post

    Hi,

    When a pane is unpinned, hover over it to expand the pane,then click the pane ,it's can't got focus.
  10. Uli
    Uli avatar
    3 posts
    Member since:
    Jun 2007

    Posted 30 Nov 2010 Link to this post

    Hi Jonam,

    I have the same problem, but I can't get it work.
    Do you have a working example?
  11. Jurjen Ladenius
    Jurjen Ladenius avatar
    25 posts
    Member since:
    Jan 2006

    Posted 04 Mar 2011 Link to this post

    I'm in exactly the same situation. Would be good if Telerik provided an example... 
  12. Kais
    Kais avatar
    18 posts
    Member since:
    Jan 2011

    Posted 07 Mar 2011 Link to this post

    Hi all, 

    Very interested in RadPane focus also, for context sensitive toolbars/options. The solution I have taken is to handle DockManager.PreviewMouseUp, and manually set "focus" (as a property on my component view models) to true for the item that was clicked. This is "good enough" for my app. Means if the user clicks on a component (ie: control inside a radpane), or on the radpane itself, I can set which is focused. Here's my code:

    private void DockManager_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
                RadPane pane = null;
                     
                if (e.Source is RadPaneGroup)
                {
                    pane = ((RadPaneGroup)e.Source).EnumeratePanes().FirstOrDefault(x => x.IsSelected);               
                }
                else if (e.Source is RadComponentPane)
                {
                    pane = (RadPane)e.Source;
                }
     
                // Focus the clicked pane       
                if (pane != null)
                {
                    var component = pane.Content as ComponentViewModelBase;
                    if (component != null)
                        component.IsFocusedComponent = true;
                }
            }

    This works fine for RadPane's docked as documents. I havent tested it elsewhere. 

    I also have a oneway binding from RadPane.IsSelected to my view model (COmponentViewModelBase) IsFocusedcomponent property to handle some spurious cases. 

    Yes ActivePane / ActivePaneChanged event would be a great feature Telerik! Hope to see this at some point. 

    Best regards, 
  13. Patrick
    Patrick avatar
    11 posts
    Member since:
    Jun 2009
Back to Top
DevCraft banner