CS0123 C#';HyperlinkButtonClick';匹配委托';RoutedEventH
本文关键字:RoutedEventH HyperlinkButtonClick CS0123 | 更新日期: 2023-09-27 18:27:28
Windows通用应用程序。我在这里并没有找到答案。我犯了一个错误CS0123 C#"HyperlinkButtonClick"没有重载匹配委托"RoutedEventHandler"。大多数相同问题的答案告诉更仔细地观察签名。或者使用更多的"global
",因为我有命名为namespace的windows。但就我而言(我认为),情况是另一回事。我只想从一页转到另一页。这看起来像是自动生成文件中的问题,但不应该是这样。第二个页面在同一个命名空间中。请帮帮我:)
代码示例:
主页.xaml
<Page
x:Class="somepath.Windows.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:somepath.Windows"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel x:Name="contentPanel" Margin="8,32,0,0">
<HyperlinkButton x:Name="nameButton" Content="name" Click="HyperlinkButtonClick" HorizontalAlignment="Stretch"/>
</StackPanel>
</Grid>
</Page>
主页.xaml.cs
using Windows.UI.Xaml.Controls;
namespace somepath.Windows
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void HyperlinkButtonClick (object sender, System.EventArgs e)
{
this.Frame.Navigate (typeof (SecondPage));
}
}
}
还有一个自动生成的文件
主页.g.cs
namespace somepath.Windows
{
partial class MainPage :
global::Windows.UI.Xaml.Controls.Page,
global::Windows.UI.Xaml.Markup.IComponentConnector,
global::Windows.UI.Xaml.Markup.IComponentConnector2
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 14.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void Connect(int connectionId, object target)
{
switch(connectionId)
{
case 1:
.
.
.
case 15:
{
this.nameButton = (global::Windows.UI.Xaml.Controls.HyperlinkButton)(target);
#line 25 "..'..'..'MainPage.xaml"
((global::Windows.UI.Xaml.Controls.HyperlinkButton)this.nameButton).Click += this.HyperlinkButtonClick;
#line default
}
break;
default:
break;
}
this._contentLoaded = true;
}
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 14.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public global::Windows.UI.Xaml.Markup.IComponentConnector GetBindingConnector(int connectionId, object target)
{
global::Windows.UI.Xaml.Markup.IComponentConnector returnValue = null;
return returnValue;
}
}
}
因此,更改以下代码:
private void HyperlinkButtonClick (object sender, System.EventArgs e)
{
this.Frame.Navigate (typeof (SecondPage));
}
对此:
private void HyperlinkButtonClick(object sender, RoutedEventArgs e)
{
this.Frame.Navigate (typeof (SecondPage));
}