Untitled
unknown
plain_text
a year ago
1.6 kB
6
Indexable
using System;
using System.ComponentModel;
using System.Windows;
namespace WpfApp
{
public partial class MainWindow : Window, INotifyPropertyChanged
{
private DateTime? _selectedDate;
private string _selectedTime;
public DateTime? SelectedDate
{
get => _selectedDate;
set
{
_selectedDate = value;
OnPropertyChanged(nameof(SelectedDate));
OnPropertyChanged(nameof(DisplayDateTime)); // Notify UI of changes
}
}
public string SelectedTime
{
get => _selectedTime;
set
{
_selectedTime = value;
OnPropertyChanged(nameof(SelectedTime));
OnPropertyChanged(nameof(DisplayDateTime)); // Notify UI of changes
}
}
public string DisplayDateTime =>
$"{SelectedDate?.ToString("d")} {SelectedTime}";
public MainWindow()
{
InitializeComponent();
DataContext = this;
// Generate ComboBox items for time
for (int hour = 0; hour < 24; hour++)
{
string time = $"{hour:D2}:00"; // Format as HH:00
TimePicker.Items.Add(time);
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}Editor is loading...
Leave a Comment