Failed to create a 'System.Windows.RoutedEventHandler' from the text 'Button_Click'
Posted
by
ay89
on Stack Overflow
See other posts from Stack Overflow
or by ay89
Published on 2013-10-24T09:08:48Z
Indexed on
2013/10/24
9:54 UTC
Read the original article
Hit count: 191
c#
In my windows phone 8 application, while trying to create a dependency property I am always getting this exception. what I am doing wrong, plz guide me.
{System.Windows.Markup.XamlParseException: Failed to create a 'System.Windows.RoutedEventHandler' from the text 'Button_Click'. [Line: 108 Position: 66] at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) at com.sap.View.HomePage.InitializeComponent()
at com.sap.View.HomePage..ctor()}
this is code-behind of Header
public static readonly DependencyProperty MenuClickProperty = DependencyProperty.Register("MenuClick", typeof(RoutedEventHandler), typeof(Header), new PropertyMetadata(OnMenuClickHandlerChanged));
public RoutedEventHandler MenuClick
{
get { return (RoutedEventHandler)GetValue(MenuClickProperty); }
set { SetValue(MenuClickProperty, new RoutedEventHandler(value)); }
}
private static void OnMenuClickHandlerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Header header = d as Header;
header.OnMenuClickHandlerPropertyChanged(e);
}
private void OnMenuClickHandlerPropertyChanged(DependencyPropertyChangedEventArgs e)
{
MenuButton.Click += MenuClick;
}
this is in my user control (Header)
<Button Click="{Binding Path=MenuClick, Source={RelativeSource Mode=Self}}" />
this is how i am including control on my Page:
<myControls:Header Title="{Binding Title}" MenuClick="Button_Click" />
this is in code-behind:
public void Button_Click(object sender, RoutedEventArgs e)
{
OpenSettings();
}
© Stack Overflow or respective owner