我在日历控件上添加了一个点击事件。但是在我的实现中,这个事件不起作用。
我在 Cal.cs 控件中的代码:
#region click
public static RoutedEvent ClickEvent =
EventManager.RegisterRoutedEvent("Click", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Cal));
public event RoutedEventHandler Click
{
add { AddHandler(ClickEvent, value); }
remove { RemoveHandler(ClickEvent, value); }
}
protected virtual void OnClick()
{
RoutedEventArgs args = new RoutedEventArgs(ClickEvent, this);
RaiseEvent(args);
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
OnClick();
}
#endregion
XAML 代码:
<Calen:Cal x:Name="Calendar" Margin="0,50,0,0" Click="Calendar_Click"/>
C#代码:
private void Calendar_Click(object sender, RoutedEventArgs e)
{
string t = "";
}
我找不到任何解决方案。我不知道为什么这段代码不能正常工作。
你能帮我解决这个问题吗?