小编Lou*_*ley的帖子

如何将EventArgs传递给DelegateCommand?

我有一个Xamarin.Forms项目.在Prism中作为MVVM框架.我有一个自定义控件(派生自CocosSharpView,但这并不重要).我正在使用参数在该类中上升自定义事件,但无法将此参数传递给ViewModel.这是代码:

视图的一部分.我正在用一些参数启动一个自定义的 OnTouched事件:

public class CustomCocosSharpView : CocosSharpView
{
    public event EventHandler<CustomEventArgs> OnTouched;
    public CCGameView gameView;

    // ... not important stuff ...

    private void OnViewCreated(object sender, EventArgs ea)
    {
        if (gameView == null)
        {
            gameView = sender as CCGameView;
            if (gameView != null)
            {
                _gameScene = new GameScene(gameView);
                _gameScene.OnTouched += (s, e) =>
                {
                    CustomEventArgs custom = new CustomEventArgs() { Foo = 4 };
                    OnTouched?.Invoke(s, custom);
                };
                gameView.RunWithScene(_gameScene);
            }
        }
        OnCreated?.Invoke(sender, ea);
    } …
Run Code Online (Sandbox Code Playgroud)

c# prism mvvm xamarin xamarin.forms

1
推荐指数
1
解决办法
1271
查看次数

标签 统计

c# ×1

mvvm ×1

prism ×1

xamarin ×1

xamarin.forms ×1