EventHandlerBehavior vs EventToCommandBehavior - xamarin

In Xamarin Forms what is the difference between the EventHandlerBehavior and EventToCommandBehavior? I have been using the former successfully, but the latter was suggested to me to use instead. EventToCommandBehavior is less verbose which is a good thing.

About difference between EventHandlerBehavior and EventToCommandBehavior, I have some point, you can take a look:
For EventHandlerBehavior, you need to install Behaviors.Forms in your project firstly, behaviors let you add functionality to controls without having to subclass them. Instead, the functionality is implemented in a behavior class and attached to the control as if it was part of the control itself. Behaviors enable you to implement code that you would normally have to write as code-behind, because it directly interacts with the API of the control in such a way that it can be concisely attached to the control and packaged for reuse across more than one app.
For EventToCommandBehavior,the EventToCommandBehavior is a custom class, there are need you create EventToCommandBehavior class derives from the BehaviorBase class firstly, then implementing Bindable Properties, for detailed info, you can take a look:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/behaviors/reusable/event-to-command-behavior
So I suggest you can use EventHandlerBehavior, because you don't need to create many code behind.
2021 Edit
EventHandlerBehavior from community-toolkit is now equivalent to EventHandlerBehavior.
Documentation:
https://learn.microsoft.com/en-us/xamarin/community-toolkit/behaviors/eventtocommandbehavior

In Xamarin Forms what is the difference between the EventHandlerBehavior and EventToCommandBehavior?
Eventhandler like:
OnTextChanged, OnSelectedIndexChanged etc are defined behind the C# code file of XAML. These methods are completely tied to your controls you define behind your pages/controls.
However the Behaviors in Xamarin allows us to ATTACH them to any View. Your behavior will know which controls it is being attached to. Hence, for those Events like OnTextChanged/OnSelectedIndexChanged can be controlled from the Behaviors.
EventToCommandBehaivor: As we already know that Behavior get attached to any view; you have to define the behavior as such that It will expose the BINDABLE property for Commands. EventToCommandBehavior is just a normal behavior control which supports binding the Command and the Eventname. Which in runtime, whenever the Event for the control get fired, your behavior will execute the Command attached making it more ViewModel friendly.
Remember if you use Events; you are writing them behind the code base than ViewModel your logics are in two separate places. If you want to properly separate the logics from View and Model then then you have to use EventToCommandBehavior.
Let me know if you need more info.

Related

Does Cocoa have something like WinAPI's DrawThemeBackground (a function that draws native controls)?

Windows API has very powerful functions that allow to draw native controls in all states:
DrawThemeBackground()
DrawThemeText()
Here's a really nice example of their usage:
Windows Visual Themes: Gallery of Parts and States?
Does Cocoa have something similar?
Apple has "soft deprecated" NSCell and the various control-specific subclasses, but you can use them for this. You create one, configure its properties, and then tell it to draw in a frame in a view.
Getting the properties just right can be tedious. You might want to create a control of the relevant kind in a test project's view (using IB) and then interrogate its cell's properties programmatically. And/or configure such a control to use a custom subclass of the corresponding cell class which logs which methods are called on it with what parameters in various scenarios.

What is imgMain control in visual Basic 6?

I'm using a VB6 application as a reference and have come across imgMain. I'm assuming its an image control, however, I cannot find the object on any of the forms. It's used to load the image. I'm just not sure what's going on with this. I'm assuming its an IMAGE CONTROL, but I cannot find this on any of the forms? it's mentioned a lot of times in teh application as it lets you view incoming faxes and stuff.
Without having a look on source code i assume It might be custom user control that was created for some reasons probably to extend basic picturebox control.
One thing i can advise you is to further inspect code and dig to code of this custom control. If code for this control is not available then see what methods and properties instances of that particular control uses and compare them with regular picturebox.

Programatically setting control properties vs. using designer

Often, when I'm looking for information of how to set certain properties of controls (I'm using Visual Studio primarily, but this question does apply to any IDE), the examples I find normally involve programatically setting said properties.
Here's an example, using the DataGridView.DefaultCellStyle property on MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.defaultcellstyle(v=vs.110).aspx
So my question is: is it better for a programmer to modify these properties by code, or is it better to use the IDE itself to change them via the properties pane? I realize that doing it the latter way will result in auto-generated code anyway, but it will be "somewhere else" in relation to the main bulk of user-generated code.
It depends on your requirements. If the app you are developing is planned to be dynamic, then it is a good idea to do it the way it is described in the reference you provided. For example, you may create a class containing the method which will set the basic settings of the gridview, so on every page you may just call this method and pass to it the gridview as a parameter instead of repeating setting the grid properties on every page.

Best practices of building composite custom controls WPF

Can You tell me about subj?
For example I need to create new custom control that must be derived from datagrid and toolbar. And I want that new control to expose/propagate properties of base controls in order they to be accessed easily. The only way I know is deriving a class. Then descendant automatically gets all properties of ancestor. But multiple deriving in C# is prohibited, so I don't know how to expose properties and other behavior of second control... Styling and templating of such custom control is also needed.
Thanks!
In WPF inheritance is "out". ;O) Actually, it was complicated before WPF already, but with WPF you get various really powerful alternatives.
For the basic control I thing you'd better go with composition, create some usercontrol and make it contain a ToolBar and a DataGrid. You can then expose these as public properties, if you need to manipulate them from outside.
For special feature additions, attached properties are a very versatile mechanism.
Watching a window from windowsclient.net is a good place to start.
Make sure you understand dependency properties well.
Reading wpf blogs is my best guest for what to do then.

How to derive class from CFindReplaceDialog? (MFC)

Is it possible to derive custom-built dialog from CFindEditDialog? I want to build a dialog template in Viasual Studio Resource Builder (to draw it), then to hide the default Find dialog window and to use my instead.
MSDN says:
To customize the dialog box, derive a
class from CFindReplaceDialog, provide
a custom dialog template, and add a
message map to process the
notification messages from the
extended controls. Any unprocessed
messages should be passed to the base
class.
Customizing the hook function is not
required
Has anyone had any experience with this?
While I don't have direct experience with this (but close others), it is quite possible and should be easish. Most of the messages will be implemented virtually, so you mearly need to override the ones you're interested in with code you add.
Code project has an artical that talks about CFindEdit. It might be helpfull
http://www.codeproject.com/KB/cpp/Media_PlayerByyazan_nemer.aspx
If you take a look at the oninitialize event for an of your dialogs, you should see how events are worked into inherited classes.

Resources