question

6666666 avatar image
0 Votes"
6666666 asked NullObjectReference-8258 answered

How to rename the Event Name in xamarin.android binding?

I am binding an .aar to android and there is one Event I have to change its name.
public event EventHandler<global::Com.xxx.xxx.A.BEventArgs> B{}

I want to change the name of B

but I can not . how to change it?

the interfaces of java is:

public static interface OnBListener{ void OnB(); }

there is a region #region "Event implementation for IOnBListener" in the cs code.

dotnet-xamarin
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

How to rename the EventArgs in xamarin.android binding

Try using argsType attribute and provide a valid C# name for the EventArgs subclass to change the name in metadata.xml like below.

<attr path="/api/package[@name='com.someapp.android.mpa.guidance']/
    interface[@name='NavigationManager.Listener']/
    method[@name='on2DSignNextManeuver']" 
    name="argsType">NavigationManager.TwoDSignNextManueverEventArgs</attr>

Check the doc:
https://docs.microsoft.com/en-us/xamarin/android/platform/binding-java-library/customizing-bindings/java-bindings-metadata#renaming-eventarg-wrapper-classes

0 Votes 0 ·

I have edit the question please check it.

0 Votes 0 ·

I do not want change the argsType but the event Name. and I do not know how to get the path of the interface since I set the path is wrong.nothing changed.

0 Votes 0 ·
Zola-2925 avatar image
0 Votes"
Zola-2925 answered

Did you finally get the correct answer? the proposed solution isn't working for me also

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NullObjectReference-8258 avatar image
0 Votes"
NullObjectReference-8258 answered NullObjectReference-8258 published

@6666666, @Zola-2925
The only way to change event name that works for me is changing of managed name of corresponding setEventListener mathod.
So if you have java sources

 /// Listener interface
 public interface OnBListener
 {
     void onB(); 
 }

And

 // Listener consumer class
 public class ListenerConsumer
 {
     public void setOnBListener(OnBListener listener) { }
 }

You can change managed name of ListenerConsumer.setOnBListener:

 <attr  
     path="/api/package[@name='com.xxx.xxx']/class[@name='ListenerConsumer']/method[@name='setOnBListener']" 
     name="managedName">SetOnDListener</attr>


In this case name of generated event in C# code will be D instead of B.









5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NullObjectReference-8258 avatar image
0 Votes"
NullObjectReference-8258 answered

Finally I found correct way to control generated event names. name="eventName" attribute can be applied to corresponding setOnListener method. For example:

 <attr
     path="/api/package[@name='com.xxx.xxx']/class[@name='ListenerConsumer']/method[@name='setOnBListener']" 
     name="eventName">D</attr>

will produce in generated C# code D event.




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.