在我的windows phone 8應用程序中,在嘗試創建依賴項屬性時,我總是收到此異常。我做錯了什麼,請指導我。無法通過文本'Button_Click'創建'System.Windows.RoutedEventHandler'
{System.Windows.Markup.XamlParseException:無法創建文本 'Button_Click' 一個 'System.Windows.RoutedEventHandler'。 System.Windows.Application.LoadComponent(Object component,Uri resourceLocator)at com.sap.View.HomePage.InitializeComponent()
at com.sap.View.HomePage .. [0126]構造函數()}
部首
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;
}
這是在我的用戶控制的,這是後臺代碼(報頭)
<Button Click="{Binding Path=MenuClick, Source={RelativeSource Mode=Self}}" />
這就是我如何包括在我的頁面控制:
<myControls:Header Title="{Binding Title}" MenuClick="Button_Click" />
這是後臺代碼:
public void Button_Click(object sender, RoutedEventArgs e)
{
OpenSettings();
}