I have the following dependency property that works fine but it does not auto update.
The dependency properties are all properties of the RegistrationButton.cls class.
public static readonly DependencyProperty DuurStilstandProperty =
DependencyProperty.Register("DuurStilstand", typeof(string), typeof(RegistrationButton), new UIPropertyMetadata(""));
.NET Wrapper public property:
public string DuurStilstand
{
get { return (string)GetValue(DuurStilstandProperty); }
set { SetValue(DuurStilstandProperty, value); }
}
What i am basically doing is trying to display a time (DateTime with default 3 min) and after that the time keeps increasing by using a timer and increments the Datetime by 1 second every second.
So on the screen it should display 00:03:00 and starts incrementing every second.
I have tried TwoWay binding (not sure if this is the issue?) but when i try the following my application crashes:
public static readonly DependencyProperty DuurStilstandProperty =
DependencyProperty.Register("DuurStilstand", typeof(string), typeof(RegistrationButton), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
The code that involved creating the button (where the time is being displayed) and the timer:
public void InitializeDispatcherTimerStilstand()
{
timerStilstand = new DispatcherTimer();
timerStilstand.Tick += new EventHandler(timerStilstand_Tick);
timerStilstand.Interval = new TimeSpan(0, 0, 1);
timerStilstand.Start();
timerStilstand.ToString();
}
private void timerStilstand_Tick(object sender, EventArgs e)
{
this.tijdStilStandRegistrationBtn.AddSeconds(1);
}
Code that creates the button:
Btn.Duurstilstand is the property that holds the time (hh:mm:ss format).
tijdStilStandRegistrationBtn = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 3, 0);
RegistrationButton btn = new RegistrationButton(GlobalObservableCollection.regBtns.Count.ToString());
btn.RegistrationCount = GlobalObservableCollection.regBtnCount;
btn.Title = "btnRegistration" + GlobalObservableCollection.regBtnCount;
btn.BeginStilstand = btn.Time;
btn.DuurStilstand = String.Format("{0:T}", this.tijdStilStandRegistrationBtn);
GlobalObservableCollection.regBtns.Add(btn);
GlobalObservableCollection.regBtnCount++;
InitializeDispatcherTimerStilstand();
Currently it only seems to display 00:03:00 as time but it does not update when my program is running.
I also tried setting the UpDateSourceTrigger to PropertyChanged but it made no difference (this is located in a Style of type RegistrationButton).
<TextBlock x:Name="tbDuurStilstand" TextWrapping="Wrap"
Text="{Binding DuurStilstand, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="7.5,5,0,0" Height="24.8266666666667"/>
EDIT
public void CreateRegistrationButton()
{
tijdStilStandRegistrationBtn = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 3, 0);
RegistrationButton btn = new RegistrationButton(GlobalObservableCollection.regBtns.Count.ToString());
btn.RegistrationCount = GlobalObservableCollection.regBtnCount;
btn.Title = "btnRegistration" + GlobalObservableCollection.regBtnCount;
btn.BeginStilstand = btn.Time;
//btn.DuurStilstand = String.Format("{0:T}", this.tijdStilStandRegistrationBtn);
GlobalObservableCollection.regBtns.Add(btn);
GlobalObservableCollection.regBtnCount++;
InitializeDispatcherTimerStilstand(btn);
}
EDIT 2:
timerStilstand.Tick += () => timerStilstand_Tick(btn); //error at ()
“Delegate ‘System.EventHandler’ does not take 0 arguments”
Kind Regards.
DateTime is an immutable struct. You have to catch the result.
I think you need:
Take 2