Display X and Y mouse coordinates
As we hover the mouse over an image element, we want to display X and Y mouse coordinates. In the following example,
- mousemove event is handled.
- Mouse_Move is the event handler method.
- The event handler stores the mouse X and Y coordinates in Coordinates property.
- The component view binds to this Coordinates property to display the X and Y coordinates.
Component View
Component Class
Event handling using a lambda expression
Instead of creating a separate named method in the component class and then specifying that method as the event handler we can use a lambda expression as the event handler directly in the HTML. An example is shown below.
Show and Hide Employee Card Footer
We want to show and hide the card footer when a button is clicked. The text on the button should also change from Show Footer to Hide Footer and vice-versa depending on the visibility of the footer.
Component View
In the example below
- onclick event is being handled
- Button_Click is the event handler method
- The text on the button is bound to ButtonText property in the component class
- The class attribute of the card-footer <div> eletemt is bound to CssClass property in the component class
Component Class
ButtonText and CssClass properties are declared in the component class. In the Button_Click event handler the values of these 2 properties (i.e ButtonText & CssClass) are being changed depending on thier current values.
No comments:
Post a Comment