I seem to have a problem displaying events in Xaml. I declared a public event handler in a custom user control.
public sealed partial class FoodItemControl : UserControl
{
public event EventHandler<StringEventArgs> thumbnailClicked;
public FoodItemControl()
{
InitializeComponent();
(this.Content as FrameworkElement).DataContext = this;
}
private void Thumbnail_Tapped(object sender, TappedRoutedEventArgs e)
{
var handler = thumbnailClicked;
if (handler != null)
{
handler(this, new StringEventArgs());
}
}
}
But when I go to assign an event to it in xaml, the event handler handler cannot be found. I.e
<local:FoodItemControl thumbnailClicked="SOMETHING" />
Am I missing something in the example I found?
EDIT : It would seem that my problem was that I defined the event as EventHandler <StringEventArgs>. It worked as soon as I changed it to just EventHandler Ie
public event EventHandler thumbnailedClicked;
However, I still do not understand why?
source
share