Reputation: 1
I am completely new to XAML.vb. when I want to calculate the age in .cs, I used to enter the following code:
private void dateTimePicker1_valueChanged (object sender, EventArgs e)
{
DateTime from = dateTimePicker1.Value;
DateTime to = dateTimePicker1.Now;
TimeSpan Tspan = to-from;
double days = Tspan.TotalDays;
textbox1.Text = (days/365)ToString("0");
}
The following code is from XAML.VB. All the functions that I used in cs before are not present.
Private Sub dob_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
{
DateTime from = dob.Value; // it doesn't exist. I found dob.GetValue but its not helping.
}
Same was with "TimeSpan" and all the other built-in functions from Microsoft they have changed it so much and much is not available on the internet. It would be great if someone has any idea about it. Thanks
Upvotes: 0
Views: 124
Reputation: 169400
DateTimePicker
is a WindowsForms control. In WPF the control is called DatePicker
and it has a SelectedDate
property that returns a Nullable(Of DateTime)
.
Try this.
XAML:
<DatePicker x:Name="dob" SelectedDateChanged="dob_SelectedDateChanged" />
<TextBox x:Name="textBox1" />
VB.NET:
Private Sub dob_SelectedDateChanged(sender As Object, e As SelectionChangedEventArgs)
Dim fromDate = dob.SelectedDate.Value
Dim toDate = DateTime.Now
Dim tspan = toDate - fromDate
Dim days = tspan.TotalDays
textBox1.Text = days.ToString
End Sub
Upvotes: 1
Reputation: 163
Timespan is available in vb too... check on this
Follwoing is the same code in vb ....
Private Sub dateTimePicker1_valueChanged(sender As Object, e As EventArgs)
Dim from As DateTime = dateTimePicker1.Value
Dim [to] As DateTime = dateTimePicker1.Now
Dim Tspan As TimeSpan = [to] - from
Dim days As Double = Tspan.TotalDays
textbox1.Text = (days / 365).ToString("0")
End Sub
Upvotes: 0