How can I add the Click routed event to my custom class?

This doesn't work. When I click the item the Click event does't occur.

    public static readonly RoutedEvent ClickEvent = ButtonBase.ClickEvent.AddOwner(typeof(HistoryListBoxItem));

    public event RoutedEventHandler Click
    {
        add { AddHandler(ClickEvent, value); }
        remove { RemoveHandler(ClickEvent, value); }
    }

Any idea?

有帮助吗?

解决方案

Your control needs to raise the event, if you do not do that nothing happens. If you want the whole control to be clickable wrap everything in a button and "forward" its click event.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top