I need to be able start a timer when my custom control is loaded. However, I need to be able to do this in the abstract class that all controls of this type inherit from.
+1
A:
The control does have a Loaded
event that you can attach to in your abstract base class in order to start the timer.
// in ctor of abstract control
_timer = new DispatcherTimer(...);
Loaded += (s,e) => _timer.Start();
aqwert
2010-09-01 05:31:42
Isn't it true that constructors are not inherited?
Justin
2010-09-01 16:09:07
Not inherited but still called when constructed via a derived type
aqwert
2010-09-01 20:22:00
Thank you! I wasted quite a bit of time on this simple misunderstanding.
Justin
2010-09-03 05:02:41
A:
Do you mean a control as abstract one. Like below?
Try the following:
public partial class MainWindow : Window
{
MyControl mycontrol;
public MainWindow()
{
InitializeComponent();
//// Your logics...
mycontrol.Dispatcher.BeginInvoke((Action)(() =>
{
/// Try invoking timer here...
}));
}
}
public abstract class MyControl: Control
{
}
HTH
Avatar
2010-09-01 17:07:50