private InvokableCallMethodAction _callMethodAction; // action used to invoke the method

        public InvokeMethodTimer()
        {
            // Create a CallMethodAction to handle invoking the method.  Use the InvokableCallMethodAction
            // class so that the Invoke method can be invoked programmatically.
            _callMethodAction = new InvokableCallMethodAction();

            // Bind the action's MethodName and TargetObject properties to the corresponding properties
            // on the InvokeMethodTimer object
            Binding b = new Binding("MethodName") { Source = this };
            BindingOperations.SetBinding(_callMethodAction, CallMethodAction.MethodNameProperty, b);

            b = new Binding("TargetObject") { Source = this };
            BindingOperations.SetBinding(_callMethodAction, CallMethodAction.TargetObjectProperty, b);

            // Add the CallMethodAction to the InvokeMethodTimer's triggers collection.  Without this,
            // invoking the action will fail silently.
            Interactivity.EventTrigger trigger = new Interactivity.EventTrigger();
            trigger.Actions.Add(_callMethodAction);
            Interactivity.TriggerCollection triggers = Interactivity.Interaction.GetTriggers(this);
            triggers.Add(trigger);

            // Initialize the timer
            _timer = new DispatcherTimer() { Interval = Delay };
            _timer.Tick += (o, e) => 
            {
                _timer.Stop();
                _callMethodAction.Invoke(null); 
            };
        }
Esempio n. 2
0
        private InvokableCallMethodAction _callMethodAction; // action used to invoke the method

        public InvokeMethodTimer()
        {
            // Create a CallMethodAction to handle invoking the method.  Use the InvokableCallMethodAction
            // class so that the Invoke method can be invoked programmatically.
            _callMethodAction = new InvokableCallMethodAction();

            // Bind the action's MethodName and TargetObject properties to the corresponding properties
            // on the InvokeMethodTimer object
            Binding b = new Binding("MethodName")
            {
                Source = this
            };

            BindingOperations.SetBinding(_callMethodAction, CallMethodAction.MethodNameProperty, b);

            b = new Binding("TargetObject")
            {
                Source = this
            };
            BindingOperations.SetBinding(_callMethodAction, CallMethodAction.TargetObjectProperty, b);

            // Add the CallMethodAction to the InvokeMethodTimer's triggers collection.  Without this,
            // invoking the action will fail silently.
            Interactivity.EventTrigger trigger = new Interactivity.EventTrigger();
            trigger.Actions.Add(_callMethodAction);
            Interactivity.TriggerCollection triggers = Interactivity.Interaction.GetTriggers(this);
            triggers.Add(trigger);

            // Initialize the timer
            _timer = new DispatcherTimer()
            {
                Interval = Delay
            };
            _timer.Tick += (o, e) =>
            {
                _timer.Stop();
                _callMethodAction.Invoke(null);
            };
        }