简体   繁体   English

uwp c# 在运行时绑定事件时将附加参数传递给导航视图事件处理程序

[英]uwp c# pass additional parameter to an navigationview event handler while binding the event at runtime

I have a navigationview and I want to pass extra argument to selection_changed event我有一个导航视图,我想将额外的参数传递给 selection_changed 事件

MUXC.NavigationView navigationview = new MUXC.NavigationView();
navigationview.SelectionChanged += new EventHandler((s, e) => Navigationview_SelectionChanged(s, e, param));

getting error for above code得到上面代码的错误

Cannot implicitly convert type 'System.Eventhandler' to 'Windows.Foundation.TypedEventHandler'无法将类型“System.Eventhandler”隐式转换为“Windows.Foundation.TypedEventHandler”

When attaching events, there is usually no need to new an EventHandler , because the type of NavigationView.SelectionChanged is TypedEventHandler , direct assignment will cause the type to mismatch.在附加事件时,通常不需要新建一个EventHandler ,因为NavigationView.SelectionChanged的类型是TypedEventHandler ,直接赋值会导致类型不匹配。

If you create a SelectionChanged event handle method, you can attach it like this:如果您创建一个SelectionChanged事件句柄方法,您可以像这样附加它:

var navigationview = new muxc.NavigationView();
navigationview.SelectionChanged += Navigationview_SelectionChanged;

private void Navigationview_SelectionChanged(muxc.NavigationView sender, muxc.NavigationViewSelectionChangedEventArgs args)
{
    // Do something...
}

From your code, you seem to have created a method with three parameters.从您的代码中,您似乎创建了一个带有三个参数的方法。 If you need to keep the param , then you need to perform some conversion.如果您需要保留param ,那么您需要执行一些转换。

navigationview.SelectionChanged += (_s, _e) =>
{
    Navigationview_SelectionChanged(_s, _e, param);
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM