没有重载匹配委托但签名是相同的

时间:2014-04-12 13:13:03

标签: c# windows-phone-8 event-handling

这是我的UserControl

    using System.Windows;

    namespace MicrosoftDaysFind22S.Controls
    {
public partial class ToggleSwitchWithHelp
{
    public ToggleSwitchWithHelp()
    {
        InitializeComponent();
    }

    public string Header
    {
        get { return (string) GetValue(HeaderProperty); }
        set
        {
            HeaderTextBlock.Text = value;
            SetValue(HeaderProperty, value);
        }
    }

    public bool IsChecked
    {
        get { return (bool)GetValue(IsCheckedProperty); }
        set
        {
            ToggleSwitcher.IsChecked = value;
            SetValue(IsCheckedProperty, value);
        }
    }

    public static readonly DependencyProperty HeaderProperty =
        DependencyProperty.Register(
            "Header", typeof(string), typeof(ToggleSwitchWithHelp), new PropertyMetadata("Неизвестная настройка"));

    public static readonly DependencyProperty IsCheckedProperty =
        DependencyProperty.Register(
            "IsChecked", typeof(bool), typeof(ToggleSwitchWithHelp), new PropertyMetadata(false));

    private void ToggleSwitcher_CheckedChange(object sender, RoutedEventArgs e)
    {
        if (ToggleSwitcher.IsChecked != null) IsChecked = (bool) ToggleSwitcher.IsChecked;
    }

    private void ToggleSwitcher_OnLoaded(object sender, RoutedEventArgs e)
    {
        ToggleSwitcher.IsChecked = IsChecked;
    }

    public delegate void NotifyCallUserHelpPageEventHandler(string settingName);

    public event NotifyCallUserHelpPageEventHandler CallUserHelpPage;

    protected virtual void OnCallUserHelpPage()
    {
        NotifyCallUserHelpPageEventHandler handler = CallUserHelpPage;
        if (handler != null) handler(Header);
    }

    private void HelpButtonClick(object sender, RoutedEventArgs e)
    {
        OnCallUserHelpPage();
    }
}
    }
页面上的

事件:

    public void ToggleSwitchWithHelp_OnCallUserHelpPage(string settingName)
    {

    }

和异常(完全和VS一样存储的字符):

  

没有重载' ToggleSwitchWithHelp_OnCallUserHelpPage'匹配委托' NotifyCallUserHelpPageEventHandler

处理程序和事件具有相同的签名,我不明白为什么我需要创建超载以及在哪里。为什么在最后没有关闭的例外情况下

我在页面上的控制权:

    <controls:ToggleSwitchWithHelp 
                    Header="Использование местонахождения"
                    IsChecked="{Binding IsAllowUseMyGeopositionSetting, Converter={StaticResource SettingsConverter}, Mode=TwoWay, Source={StaticResource AppSettings}}" 
                    CallUserHelpPage="ToggleSwitchWithHelp_OnCallUserHelpPage"/>

最后调查显示,如果从代码隐藏中添加相同的事件,所有工作都很好

   public SettingsPage()
    {
        InitializeComponent();

        ToggleSwitchWithHelp.CallUserHelpPage += ToggleSwitchWithHelp_OnCallUserHelpPage;
    }

为什么它不适用于布局?

0 个答案:

没有答案