0
我想向文本框中添加點擊事件,但我的代碼無法正常工作。單擊文本框時,該事件不會運行。文本框上的點擊事件
這裏是背後
public class Day : INotifyPropertyChanged
{
public delegate void ClickEventHandler(object sender, ClickEventArgs e);
public event Application_IAD.TEST.Day.ClickEventHandler onClick;
protected virtual void onTheClick()
{
if (onClick != null) onClick(this, new ClickEventArgs(new Day()));
}
}
public class Cal : Control
{
public ObservableCollection<Day> Days { get; set; }
public event EventHandler<ClickEventArgs> DayClick;
public Cal()
{
DataContext = this;
CurrentDate = DateTime.Today;
DayNames = new ObservableCollection<string> {"Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"};
Days = new ObservableCollection<Day>();
BuildCalendar(DateTime.Today);
}
public void BuildCalendar(DateTime targetDate)
{
Days.Clear();
//Show 6 weeks each with 7 days = 42
for (int box = 1; box <= 42; box++)
{
Day day = new Day {Date = d, Enabled = true, IsTargetMonth = targetDate.Month == d.Month};
day.onClick += test;
}
}
private void test(object sender, ClickEventArgs e)
{
DayClick(this, new ClickEventArgs(sender as Day));
}
}
代碼這裏是XAML
<Calen:Cal x:Name="Calendar" Margin="0,50,0,0" DayChanged="Calendar_DayChanged" DayClick="Calendar_DayClick"/>
我不知道哪裏出錯或不知道怎樣做才能解決它。