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
11 Answers, 1 is accepted
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.
George
the Telerik team
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
List<
RadPane
> list = radDocking1.Panes.ToList();
list = list.Where(x => x.IsSelected && x.IsFocused ).ToList();
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
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;
}
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.
George
the Telerik team
When a pane is unpinned, hover over it to expand the pane,then click the pane ,it's can't got focus.
I have the same problem, but I can't get it work.
Do you have a working example?
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,