ios - 绑定(bind)到 MvvmCross 中的 UIBarButtonItem 事件

标签 ios mvvmcross xamarin.ios

使用 MvvmCross 创建从 UIBarButtonItemMvxCommand 的绑定(bind)的正确方法是什么?

这对我不起作用->

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();
    this.AddBindings (new Dictionary<object, string> (){
       {MyButton, "{'Clicked':{'Path':'MyCommand'}}"}
    });
}

我在控制台中没有收到任何错误。我可以通过避免绑定(bind)来解决问题,但你知道,如果所有内容都绑定(bind)的话看起来最好。

最佳答案

假设条形按钮 - MyButton - 在您调用 AddBindings 之前已初始化,那么我认为您的代码应该可以工作。

我将 Conference 示例中的 WelcomeView 中的代码修改为下面的代码,它似乎可以工作...

        var s = new UIBarButtonItem()
        {
            Title = "Click me"
        };

        NavigationItem.SetRightBarButtonItem(s, false);

        this.AddBindings(new Dictionary<object, string>()
            {
                { Button1, "TouchUpInside ShowSponsorsCommand" },               
                { Button2, "TouchUpInside ShowExhibitorsCommand" },             
                { Button3, "TouchUpInside ShowMapCommand" },                
                { Button4, "TouchUpInside ShowAboutCommand" },  
            { s, "Clicked ShowMapCommand" },
            });

        //NavigationItem.SetRightBarButtonItem(new UIBarButtonItem("Tweet", UIBarButtonItemStyle.Bordered, (sender, e) => ViewModel.DoShareGeneral()), false);

很抱歉,如果这个“对我有用”的答案对您的机器没有帮助:/

为了确保它在 Release模式下工作,您可能需要在某处添加一些 UIBarButtonItem.Clicked 代码。

如果您希望从绑定(bind)中获得更多跟踪信息,那么您可以设置一个诊断跟踪级别(但这可能会变得非常冗长)。

可能值得检查您的 MyCommand 是否被调用但不知何故失败 - 这尤其可能发生在电子邮件、电话、推文等并不总是在模拟器上工作的事情上。

关于ios - 绑定(bind)到 MvvmCross 中的 UIBarButtonItem 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15200966/

相关文章:

xamarin.android - 将多个目标绑定(bind)到同一源

xamarin.ios - 我如何从按钮调用异步方法

ios - 在 CoreML VNCoreMLRequest 之前触发时 ActivityIndi​​cator 不显示

ios - 需要 wantsFullScreenLayout 行为与 iOS 7 上的非半透明栏

json - MvvmCross:JSON 的反序列化错误

ios - 带有导航 Controller 的不同页面上的 Xamarin.SideBar

xamarin.ios - 激活单点触控

iphone - 设置 UIImagePickerController 的 UIBarStyle

ios - 如何创建免费的 iOS 开发配置文件

c# - 为不同的 MvvmCross (v3) 平台处理 GoBack 的最佳方法是什么