Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8353821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:22:29+00:00 2026-06-09T09:22:29+00:00

I’m looking for a way to do a Touch command binding between axml and

  • 0

I’m looking for a way to do a “Touch” command binding between axml and ViewModel, or some else like FocusChanged etc.

A simple “Click” command works fine like so:
local:MvxBind=”{‘Touch’:{‘Path’:’CameraButtonCommand’}}” />

    public IMvxCommand CameraButtonCommand
    {
        get
        {
            return new MvxRelayCommand(
                () =>
                {
                    RequestNavigate<AugRealityViewModel>(true);
                })
            ;
        }
    }

However, I’ve tried other event types for the controll(in this case it’s ImageButton) and they are not being processed. When I’ve checked the events listings in the View Class I see those:

    public event EventHandler Click;
    public event EventHandler<View.CreateContextMenuEventArgs> ContextMenuCreated;
    public event EventHandler<View.FocusChangeEventArgs> FocusChange;
    public event EventHandler<View.KeyEventArgs> KeyPress;
    public event EventHandler<View.LongClickEventArgs> LongClick;

Only Click event has the general EventHandler attached to it, while other have genericed EventHandlers, and I’m wondering if that’s the reason why it doesn’t work.

I’ve also tried to attach a method to those events in the View class getting the proper control by FindViewById method and it works as expected this time around. But somehow I can’t do it in the axml through Commands.

Also one more thing. The “Click” event is sending the “EventArgs” object as one of the parameters, and also the object reference. I can see that with ease if I do this behaviour in View Class, but when I do this by binding, I don’t see those arguments when I’m processing the Command in ViewModel.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:22:31+00:00Added an answer on June 9, 2026 at 9:22 am

    The framework can automatically bind any events which require EventHandler types. However, for any events which require a templated EventHandler (with custom EventArgs) then you are correct – you’ll need to include a custom Binding.

    The good news is that custom bindings are easy to write and to include.

    For example, to bind:

    public event EventHandler<View.LongClickEventArgs> LongClick;
    

    you can include something like:

    public class LongPressEventBinding
        : MvxBaseAndroidTargetBinding
    {
        private readonly View _view;
        private IMvxCommand _command;
    
        public LongPressEventBinding(View view)
        {
            _view = view;
            _view.LongClick += ViewOnLongClick;
        }
    
        private void ViewOnLongClick(object sender, View.LongClickEventArgs eventArgs)
        {
            if (_command != null)
            {
                _command.Execute();
            }
        }
    
        public override void SetValue(object value)
        {
            _command = (IMvxCommand)value;
        }
    
        protected override void Dispose(bool isDisposing)
        {
            if (isDisposing)
            {
                _view.Click -= ViewOnLongClick;
            }
            base.Dispose(isDisposing);
        }
    
        public override Type TargetType
        {
            get { return typeof(IMvxCommand); }
        }
    
        public override MvxBindingMode DefaultMode
        {
            get { return MvxBindingMode.OneWay; }
        }
    }
    

    Which can be configured in setup using something like:

        protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry)
        {
            base.FillTargetFactories(registry);
    
            registry.RegisterFactory(new MvxCustomBindingFactory<View>("LongPress", view => new LongPressEventBinding(view)));
        }
    

    Note that you can’t write a single class that binds to all the different event types – as the compiler requires you to include the correct Type for the EventArgs. However, you could fairly easily change public class LongClickEventBinding to something like public class CustomEventBinding<TViewType, TEventArgsType> if you wanted to.


    With regards to what argument you should pass into the IMvxCommand Execute method, I guess this depends a bit on the method in question, and it also depends on whether you need the ViewModel to support multiple platforms, or whether it is just for Android.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.