Windows.Ui.Xaml.Controls.Primitives.ButtonBase不能显式调用运算符或访问器

本文关键字:调用 运算符 访问 不能 Xaml Ui Controls Primitives ButtonBase Windows | 更新日期: 2023-09-27 18:21:48

我得到以下错误:

Windows.Ui.Xaml.Controls.Primitives.ButtonBase无法显式调用运算符或访问器

错误发生在以下代码处:

 case 11:
                {
                    ButtonBase buttonBase2 = (ButtonBase)target;
                    WindowsRuntimeMarshal.AddEventHandler<RoutedEventHandler>(new Func<RoutedEventHandler, EventRegistrationToken>(buttonBase2, ButtonBase.add_Click), new Action<EventRegistrationToken>(buttonBase2, ButtonBase.remove_Click), new RoutedEventHandler(this.RemoveTrack));
                    break;
                }

Windows.Ui.Xaml.Controls.Primitives.ButtonBase不能显式调用运算符或访问器

这是一个编译时错误。从MSDN WindowsRuntimeMarshal.AddEventHandler方法:

This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.

如果要向Click事件添加/删除事件处理程序,请使用+=-=运算符

buttonBase2.Click += this.RemoveTrack;

buttonBase2.Click -= this.RemoveTrack;