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.
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();
Not sure what's your issue is? There are three timers available in .NET and you should be probably able use any of them. Check this article to understand choices and differences between them.
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
精彩评论