Thanks Nikolay,
Chekcing the ElementTree in the TransactionBlockEnded event handler was the missing bit. Also solved a bunch of other problems I had before when the tool window was closed or re-docked etc. Used to check for these events and call StopFlashing() in several places - the code is much cleaner now.
One has to be very careful about the order of events, your sample code for example does not work when you first autohide and then start the flashing.
This is the code that I came up with so far. It inherits from the Telerik Tool Window. You can call StartFlashing() or StopFlashing() on it, plus it stops when it becomes the active window.
using
System;
using
Telerik.WinControls.UI.Docking;
using
Telerik.WinControls.Primitives;
namespace
Octopus2.Controls
{
class
FlashingToolWindow : ToolWindow
{
FlashManager flashManager =
null
;
FillPrimitive fill =
null
;
bool
initialized =
false
;
bool
windowShouldFlash =
false
;
public
void
StartFlashing()
{
windowShouldFlash =
true
;
if
(
this
.DockState == DockState.Docked ||
this
.DockState == DockState.AutoHide||
this
.DockState==DockState.Floating)
{
fill =
null
;
if
(
this
.DockState == DockState.Docked||
this
.DockState == DockState.Floating)
{
if
(
this
.TabStrip.HasChildren)
{
fill = (FillPrimitive)
this
.TabStripItem.Children[0];
}
}
if
(
this
.DockState == DockState.AutoHide)
{
if
(
this
.AutoHideTab.Children.Count > 0)
{
fill = (FillPrimitive)
this
.AutoHideTab.Children[0];
}
}
if
(fill !=
null
)
{
flashManager =
new
FlashManager(fill);
flashManager.StartFlashing();
}
if
(!initialized)
{
initialized =
true
;
this
.DockManager.ActiveWindowChanged +=
new
DockWindowEventHandler(DockManager_ActiveWindowChanged);
this
.DockManager.TransactionBlockEnded +=
new
EventHandler(DockManager_TransactionBlockEnded);
}
}
}
void
DockManager_TransactionBlockEnded(
object
sender, EventArgs e)
{
//
// the TabStripItem or the AutoHideTab may no longer be available when docking changes
//
if
(fill !=
null
)
{
if
(fill.ElementTree ==
null
)
{
if
(flashManager !=
null
)
{
flashManager.StopFlashing();
flashManager =
null
;
}
if
(windowShouldFlash)
{
StartFlashing();
}
}
}
}
void
DockManager_ActiveWindowChanged(
object
sender, DockWindowEventArgs e)
{
if
(e.DockWindow.Name ==
this
.Name)
{
StopFlashing();
}
}
public
void
StopFlashing()
{
windowShouldFlash =
false
;
if
(flashManager !=
null
)
{
flashManager.StopFlashing();
}
}
}
}