Harshal Suthar, Author at Tech Web Space Let’s Make Things Better Wed, 12 Oct 2022 13:32:39 +0000 en-US hourly 1 https://wordpress.org/?v=6.2.3 https://www.techwebspace.com/wp-content/uploads/2015/07/unnamed-150x144.png Harshal Suthar, Author at Tech Web Space 32 32 A Step-By-Step Guide to Integrating Material UI Into React https://www.techwebspace.com/a-step-by-step-guide-to-integrating-material-ui-into-react/ Wed, 12 Oct 2022 13:32:30 +0000 https://www.techwebspace.com/?p=60610 What is a Material UI? Material UI is a free and open-source React component library based on Google’s Material Design. It comes with a large number of prebuilt components that are ready for use in production straight away. This is one of...

The post A Step-By-Step Guide to Integrating Material UI Into React appeared first on Tech Web Space.

]]>
What is a Material UI?

Material UI is a free and open-source React component library based on Google’s Material Design. It comes with a large number of prebuilt components that are ready for use in production straight away. This is one of the primary reasons why companies want to hire React developers for application development. Let’s take a closer look at the advantages of Material UI.

What are the advantages of Material UI?

Access to Systematic Documentation:

Like all other products of Google, Material UI also comes with the Google “advantage” and in this case, there exists detailed documentation to help designers understand, explore and start using the set of guidelines without any trouble. This support makes it easier for any designer who wants to learn the material UI and anyone can easily start using material UI.

The Element of Flexibility:

Material Designs also provide some flexibility, despite the fact that there are predefined guidelines for each design scenario. Designers are free to manipulate the various design elements and choose how to implement them. Therefore, it provides the perfect balance of rules and flexibility, allowing designers to be creative.

Classic Design System for Mobile Apps:

Material Designs is one of the most compatible mobile app design systems because it was originally developed for designing Android applications. With more mobile apps as smartphone users grow, this design system is gaining popularity among UI designers around the world. Material Designs has also announced a dark theme that gives designers more flexibility in experimenting with the theme.

Cross-team collaboration:

The material UI’s intuitive developer experience lowers the barriers to entry for back-end developers and non-technical designers, allowing teams to collaborate more effectively.

Trusted by thousands of organizations: 

Material UI has the largest UI community for React. It’s about as old as React. Material UI has big community support rather than other UI systems.

Every technology has some advantages and disadvantages. We have seen how material UI is providing lots of advantages to us. Now we will see some disadvantages of material UI.

Harder to Implement for Beginner:

For the beginner, it is difficult to use the material UI. Material UI’s specification is more complicated and harder to implement than other styles like flat design.

Easily Identifiable:

Material Design is immediately identifiable and is strongly associated with Google and, specifically, Android. While this isn’t necessarily a bad thing for everyone, it’s potentially a negative for some.

Overuse of images and colours can be distracting:

Material Design still promotes use of vibrant colours and images in its spec. While this can make an interface lively, this style is prone to overuse and can be very distracting to users trying to get something done.

For example, the following menu appears several times in the Material Design documents. It uses an unnecessarily high-contrast header background with multiple layers and off-grid lines which may be fun to look at once, but is functionally crappy because it makes the text hard to read and can get annoying when the menu is opened multiple times:

Rectangular Buttons and Cards:

Material design uses a lot of rectangles with sharp corners in its elements. This makes elements less visually appealing to users.

What are the prerequisites for using material UI?

For material UI, make sure that you have npm installed on your computer. Here, We use npm to download and install the dependencies. You also need a code editor.

How to install material UI? To install and save in material UI, you have to use the following command, which will install all the dependencies of material UI.

npm install @mui/material @emotion/react @emotion/styled

Now we see the practical with Material UI

  • 1. Create React project
npx create-react-app material-ui-with-react
  • 2. Import the component that you want to use in the React

You can import any component just by passing its name. Here, we are importing the button.

import { Button } from '@mui/material';

App.js

import React from 'react'
import { Button } from '@mui/material';
function App() {
  return (
    

Hello, This is material UI with ReactJS.

); } export default App;

Material UI comes with lots of CSS you have to just pass the props for it. Like if we want backgroundColor of the button something different then we have one Prop named variant. You can see in the below code in the button we have passed contained a variant that will add blue color in the background. For outlined Button you can use variant= “outlined”, this will create an outlined button.

You can see the below-given output of the above code. Here are different variant images of buttons.

Figure 1. variant = “contained”

Now, we see the output of the variant outlined. We just have to make changes in props. Like below:

Figure 2. variant = “outlined”

Some examples of Components in Material UI:

  • Typography -> To present your design and content as clearly and efficiently as possible.                                                               
  • Tooltip -> Display informative text when users hover over, focus on, or tap an element.
  • Layout -> Use uniform elements and spacing to encourage consistency across platforms, environments, and screen sizes.
  • Box -> Serves as a wrapper component for most of the CSS utility needs.
  • Container -> Centres your content horizontally. It’s the most basic layout element.
  • Grid -> Adapts to screen size and orientation, ensuring consistency across layouts.
  • Text Field -> Let users enter and edit text.

Icons in material UI:

    To install material Ui icons, the following commands are required:-

  npm install @mui/icons-material @mui/material @emotion/styled @emotion/react

For detailed Icons of Material Ui below is the following link:-

To use these icons in the project, just select any of these icons and copy the code and then

paste it on the top level of your component and then use it.

import Box from '@mui/material/Box';
import Icon from '@mui/material/Icon';
import { visuallyHidden } from '@mui/utils';
// ...
add_circle
Create a user

Styling Of Components

There are three APIs available for generating and applying styles, but they all share the same underlying logic.

Hook API

import * as React from 'react';
import { makeStyles } from '@mui/styles';
import Button from '@mui/material/Button';

const useStyles = makeStyles({
  root: {
    background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
    border: 0,
    borderRadius: 3,
    boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
    color: 'white',
    height: 48,
    padding: '0 30px',
  },
});

export default function Hook() {
  const classes = useStyles();
  return ;
}


Styled components API

Note: this only applies to the calling syntax – style definitions still use a JSS object. You can also change the behaviour with some limitations.

import * as React from 'react';
import { styled } from '@mui/styles';
import Button from '@mui/material/Button';

const MyButton = styled(Button)({
  background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
  border: 0,
  borderRadius: 3,
  boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
  color: 'white',
  height: 48,
  padding: '0 30px',
});

export default function StyledComponents() {
  return Styled Components;
}


Styled with styled-components API

Higher-order component API

import * as React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@mui/styles';
import Button from '@mui/material/Button';

const styles = {
  root: {
    background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
    border: 0,
    borderRadius: 3,
    boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
    color: 'white',
    height: 48,
    padding: '0 30px',
  },
};

function HigherOrderComponent(props) {
  const { classes } = props;
  return ;
}

HigherOrderComponent.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(HigherOrderComponent);

Conclusion

For each front-end developer, the material UI is just as important as bootstrap and fluent UI. It is the gateway for any business to acquire a customer and leads. Therefore, keeping a prior focus on user requirements is essential. Here, in this blog, we have learned what is material UI, we have seen various advantages and disadvantages of using material UI, and last, we have seen one practical integration of material UI with ReactJS.

Vinod Satapara – Technical Director, iFour Technolab Pvt. Ltd.

Technocrat and entrepreneur with years of experience building large-scale enterprise web, cloud, and mobile applications using the latest technologies like ASP.NET, CORE, .NET MVC, Angular, and Blockchain. Keen interested in addressing business problems using the latest technologies and have been associated with a reputed .NET development company.

The post A Step-By-Step Guide to Integrating Material UI Into React appeared first on Tech Web Space.

]]>
Explain Filter Overrides in Asp.Net MVC 2022 https://www.techwebspace.com/explain-filter-overrides-in-asp-net-mvc-2022/ Tue, 05 Jul 2022 02:39:16 +0000 https://www.techwebspace.com/?p=58939 What are Filter overrides in MVC? “Filter overrides” is one of the critical features of ASP.NET MVC used while .NET development. Its main purpose is to exclude action, method, or controller from the controller level filter or global filter. It allows us...

The post Explain Filter Overrides in Asp.Net MVC 2022 appeared first on Tech Web Space.

]]>
What are Filter overrides in MVC?

“Filter overrides” is one of the critical features of ASP.NET MVC used while .NET development. Its main purpose is to exclude action, method, or controller from the controller level filter or global filter. It allows us to clear specific types of filters that might be created at the higher scopes.

Let’s say, there is a scenario where we created a global action filter or a controller-level action filter, now we have an action method on which we don’t want to use an action filter in Asp.Net MVC. In this scenario, the filter override feature is used.

In MVC, there are five types of filters available.

  1. Action filters
  2. Authentication filters
  3. Authorization filters
  4. Exception filters
  5. Result filters

Therefore, we have five filter overrides according to prior filters:

  1. OverrideActionFiltersAttribute
  2. OverrideAuthenticationAttribute
  3. OverrideAuthorizationAttribute
  4. OverrideExceptionAttribute
  5. OverrideResultAttribute

We can mark any action method with a corresponding override filter attribute that essentially clears all the filters at the controller level or global level.

How to apply the Authorization Filter at the controller level?

In this following example, we will discuss in detail the Filter Override. Here, the Authorization Filter is applied at the controller level. Thus, all the action methods of the home controller can be accessed by the Admin user only. Now, we will bypass or exclude the Authorize Filter from the “About” method.

[Authorize(Users="Admin")]  
public class HomeController : Controller  
{  
    public ActionResult Index()  
    {  
        ViewBag.Message = "iFour Technolab";  
        return View();  
    }   
    public ActionResult About()  
    {  
        return View();  
    }  
}

Here, we will mark the “About” method with the “OverrideAuthorization” attribute. Now, all the action methods of the home controller are available to access for Admin users except the “About” action method without any type of authorization.

[Authorize(Users="Admin")]  
public class HomeController : Controller  
{  
    public ActionResult Index()  
    {  
        ViewBag.Message = "Welcome to ASP.NET MVC!";  
        return View();  
    }  
    [OverrideAuthorization]  
    public ActionResult About()  
    {  
        return View();  
    }  
}  

Example

Open the Visual Studio and click Create New Project.

Figure 1: Visual Studio Home

After selecting New Project, we will select Web Templates from the left side of the panel after the selection of Web Template, we will see only one project template in that portion which is “ASP.NET Web Application”, select that.

Figure 2: Visual Studio Project Creation

After that, we will name the project “MVC5DEMO5” and click the OK button. A new popup will be shown in the same tab.

Figure 3: Visual Studio Project Selection

Here, we will choose the MVC Project template and then choose the Authentication type as Choose Individual User Accounts.

Figure 4: Selection of Authentication

When we choose this option for Authentication of application, it will be configured to use ASP.NET Identity where the User can register in the Application and sign in using the credentials. New features of MVC 5 also support Sign in via Facebook, Google, Microsoft, and Twitter. All the data are collected and stored in the SQL Server database.

When you select the Authentication type as Individual User Accounts, and click on OK, you will see a progress bar while project creation.

Figure 5: Project Created Successfully

After successfully creating the project, you will be shown Readme HTML page with links on the page.

Figure 6: Home Page

Now, we will add the Filter folder to the Project. For that, right-click on MVC5DEMO5 and select Add, and inside that select New Folder.

Figure 7: Visual Studio Project Folders

After successfully creating the folder, we will add Filters in this folder to validate whether the user has logged in to the application or not.

Now, we are going to add Filter in the Filters folder with the name UserAuthenticationFilter and it will inherit a class FilterAttribute and IAuthenticationFilter, and in this filter, we are just going to check Session is IsNullOrEmpty; If it is NULL or Empty, then we are going to redirect it to Error View, if not then it will allow executing Action Method.

Here is the code snipped for UserAuthenticationFilter:

using System;
using System.Web.Mvc;
using System.Web.Mvc.Filters;

namespace MVC5DEMO5.Filters
{
    public class UserAuthenticationFilter : FilterAttribute, IAuthenticationFilter 
    {
        public void OnAuthentication(AuthenticationContext filterContext)
        {
            if (string.IsNullOrEmpty(Convert.ToString(filterContext.HttpContext.Session["UserID"])))
            {
                filterContext.Result = new ViewResult
                {
                    ViewName = "Error"
                };

            }
        }

        public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
        {
           
        }
    }
}

Next, we will apply the UserAuthenticationFilter Filter on HomeController. This controller is created by default when we have created a project.

Figure 8: Adding the Controller

To access controller for a user, he must have Session[“UserID”]. It wll get him to error view if the ID is found Null or empty.

using MVC5DEMO5.Filters;
using System.Web.Mvc;

namespace MVC5DEMO5.Controllers
{
	[UserAuthenticationFilter]
	public class HomeController : Controller
	{
		public ActionResult Index()
		{
			return View();
		}
		public ActionResult About()
		{
			ViewBag.Message = "Your application description page.";
			return View();
		}
		public ActionResult Contract()
		{
			ViewBag.Message = "Your Contact page.";
			return View();
		}
	}
}

After saving the changes, let’s run the application using the following URL:

http://localhost:xxxxx/home/Index

The following Error View screen will appear whenever we will try to open any pages among Index, About and Contact.

Figure 9: Error View

Now, we will apply the [OverrideAuthentication] filter on the About Action Method as below:

using MVC5DEMO5.Filters;
using System.Web.Mvc;

namespace MVC5DEMO5.Controllers
{
    [UserAuthenticationFilter]
    public class HomeController : Controlller
    {
        public ActionResult Index()
        {
            return View();
        }
        [OverrideAuthentication]
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page."
            return View();
        }
        public ActionResult Contact()
        {
                        ViewBag.Message = "Your contact page."
            return View();
        }
    }
}  

There will be three possible outcomes:

  1. If we access the Index Action Method, it will redirect to Error view as UserAuthenticationFilter is applied on Controller. It means that it is applied to all the Action Methods inside that Controller.
  2. If we access the Contact Action Method, it too will redirect to Error view as UserAuthenticationFilter is applied on Controller. It means that it is applied to all the Action Methods inside that Controller.
  3. If we access the About Action method, it will not redirect to Error view as we have applied the OveerideAction Filter on this action method.

If we want to override the Action filter then we must only apply the OverrideActionFilters but if we apply any other filter such as OverrideAuthentication or OverrideAuthorization or OverrideResultFilter or OverrideExceptionFilters, it won’t work.

Conclusion

In this article, we learned what is override in MVC, the types of overrides, and an example of overrides used in an MVC application. This will provide you with an easy and complete understanding of the Filter override procedures.

The post Explain Filter Overrides in Asp.Net MVC 2022 appeared first on Tech Web Space.

]]>
Explain Controls Template in Xamarin Forms https://www.techwebspace.com/explain-controls-template-in-xamarin-forms/ Sun, 03 Jul 2022 08:22:45 +0000 https://www.techwebspace.com/?p=58892 For example, to create behaviors with Xamarin.Forms and seamlessly redefine the UI, a control template with custom control can be developed efficiently.

The post Explain Controls Template in Xamarin Forms appeared first on Tech Web Space.

]]>
In Xamarin, the visual structure of ContentPage-derived pages and ContentView-derived custom controls can be defined using Forms control templates. The user interface (UI) for a custom control, or page, is separated from the logic that implements the control or page using control templates. At a pre-defined position, more content can be inserted into the templated custom control or templated page.

For example, to create behaviors with Xamarin.Forms and seamlessly redefine the UI, a control template with custom control can be developed efficiently. The needed custom control instance can then consume the control template. A control template, on the other hand, can be used to specify any common UI that will be shared by several pages in an application.

Create a Control Template

The code for a CardView custom control is shown in the following example:

public class CardView : ContentView
{
    public static readonly BindableProperty CardTitleProperty = BindableProperty.Create(nameof(CardTitle), typeof(string), typeof(CardView), string.Empty);
    public static readonly BindableProperty CardDescriptionProperty = BindableProperty.Create(nameof(CardDescription), typeof(string), typeof(CardView), string.Empty);
    // ...

    public string CardTitle
    {
        get => (string)GetValue(CardTitleProperty);
        set => SetValue(CardTitleProperty, value);
    }

    public string CardDescription
    {
        get => (string)GetValue(CardDescriptionProperty);
        set => SetValue(CardDescriptionProperty, value);
    }
    // ...
}

A custom control that shows data in a card-like arrangement is represented by the CardView class, which inherits from the ContentView class. The data it presents is represented by properties that are backed by bindable properties. The CardView class, on the other hand, does not define any user interface. Instead, a control template will be used to define the user interface. See Xamarin.Forms ContentView for more information on creating Content View-derived custom controls.
The ControlTemplate type is used to generate a control template. You use View objects to design the UI for a custom control or page when you create a ControlTemplate. Only one View can be the root element of a ControlTemplate. Other View objects are normally found in the root element. The visual structure of the control is made up of a collection of objects.



The ControlTemplate type is used to generate a control template. You use View objects to design the UI for a custom control or page when you create a ControlTemplate. Only one View can be the root element of a ControlTemplate. Other View objects are normally found in the root element. The visual structure of the control is made up of a collection of objects. If you declare a control template in the root element of your application definition XAML file, for example, you can use it everywhere in your app. Only that page can use the control template if you define it in a page. See Xamarin.Forms Resource Dictionaries for additional information about resources.

A ControlTemplate for CardView objects is shown in the XAML sample below:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             ...>
    <ContentPage.Resources>
      <ControlTemplate x:Key="CardViewControlTemplate">
          <Frame BindingContext="{Binding Source={RelativeSource TemplatedParent}}"
                 BackgroundColor="{Binding CardColor}"
                 BorderColor="{Binding BorderColor}"
                 CornerRadius="5"
                 HasShadow="True"
                 Padding="8"
                 HorizontalOptions="Center"
                 VerticalOptions="Center">
              <Grid>
                  <Grid.RowDefinitions>
                      <RowDefinition Height="75" />
                      <RowDefinition Height="4" />
                      <RowDefinition Height="Auto" />
                  </Grid.RowDefinitions>
                  <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="75" />
                      <ColumnDefinition Width="200" />
                  </Grid.ColumnDefinitions>
                  <Frame IsClippedToBounds="True"
                         BorderColor="{Binding BorderColor}"
                         BackgroundColor="{Binding IconBackgroundColor}"
                         CornerRadius="38"
                         HeightRequest="60"
                         WidthRequest="60"
                         HorizontalOptions="Center"
                         VerticalOptions="Center">
                      <Image Source="{Binding IconImageSource}"
                             Margin="-20"
                             WidthRequest="100"
                             HeightRequest="100"
                             Aspect="AspectFill" />
                  </Frame>
                  <Label Grid.Column="1"
                         Text="{Binding CardTitle}"
                         FontAttributes="Bold"
                         FontSize="Large"
                         VerticalTextAlignment="Center"
                         HorizontalTextAlignment="Start" />
                  <BoxView Grid.Row="1"
                           Grid.ColumnSpan="2"
                           BackgroundColor="{Binding BorderColor}"
                           HeightRequest="2"
                           HorizontalOptions="Fill" />
                  <Label Grid.Row="2"
                         Grid.ColumnSpan="2"
                         Text="{Binding CardDescription}"
                         VerticalTextAlignment="Start"
                         VerticalOptions="Fill"
                         HorizontalOptions="Fill" />
              </Grid>
          </Frame>
      </ControlTemplate>
    </ContentPage.Resources>
    ...
</ContentPage>

A key must be supplied using the x:Key attribute when a ControlTemplate is declared as a resource so that it can be identified in the resource dictionary. In this case, the CardViewControlTemplate’s root element is a Frame object. The Frame object uses the RelativeSource markup extension to set its BindingContext to the templated parent, which is the runtime object instance to which the template will be applied. The visual framework of a CardView object is defined by the Frame object, which combines Grid, Frame, Image, Label, and BoxView elements. Because these objects inherit the BindingContext from the root Frame element, their binding expressions resolve to CardView attributes. See Xamarin for more details on the RelativeSource markup extension. Relative Bindings are formed.

Consume a Control Template

By setting the ControlTemplate attribute to the control template object, a ControlTemplate can be applied to a Content View-derived custom control. Similarly, by setting the ControlTemplate property of a Content Page-derived page to the control template object, a ControlTemplate can be applied to the page. When a ControlTemplate is applied to a templated custom control or templated page at runtime, all of the controls defined in the ControlTemplate are added to the visual tree of the templated custom control or templated page.

Each CardView object’s ControlTemplate attribute is allocated the CardViewControlTemplate in the following example:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:controls="clr-namespace:ControlTemplateDemos.Controls"
             ...>
    <StackLayout Margin="30">
        <controls:CardView BorderColor="DarkGray"
                           CardTitle="John Doe"
                           CardDescription="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elit dolor, convallis non interdum."
                           IconBackgroundColor="SlateGray"
                           IconImageSource="user.png"
                           ControlTemplate="{StaticResource CardViewControlTemplate}" />
        <controls:CardView BorderColor="DarkGray"
                           CardTitle="Jane Doe"
                           CardDescription="Phasellus eu convallis mi. In tempus augue eu dignissim fermentum. Morbi ut lacus vitae eros lacinia."
                           IconBackgroundColor="SlateGray"
                           IconImageSource="user.png"
                           ControlTemplate="{StaticResource CardViewControlTemplate}" />
        <controls:CardView BorderColor="DarkGray"
                           CardTitle="Xamarin Monkey"
                           CardDescription="Aliquam sagittis, odio lacinia fermentum dictum, mi erat scelerisque erat, quis aliquet arcu."
                           IconBackgroundColor="SlateGray"
                           IconImageSource="user.png"
                           ControlTemplate="{StaticResource CardViewControlTemplate}" />
    </StackLayout>
</ContentPage>

The controls in the CardViewControlTemplate are included in the visual tree for each CardView object in this example. The Frame and its children resolve their binding expressions against the properties of each CardView object since the root Frame object for the control template assigns its BindingContext to the templated parent.

The CardViewControlTemplate is applied to the three CardView objects in the following                                               

Consume a Control template

Pass Parameter with TemplateBinding

The TemplateBinding markup extension links a public property defined by the templated custom control or templated page to a property of an element in a ControlTemplate. When you utilize a TemplateBinding, you allow the control’s properties to be used as template parameters. When a property on a templated custom control or templated page is set, the value is sent to the element with the TemplateBinding.

The following XAML example uses the TemplateBinding markup extension to create a ControlTemplate for CardView objects:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             ...>
    <ContentPage.Resources>
        <ControlTemplate x:Key="CardViewControlTemplate">
            <Frame BackgroundColor="{TemplateBinding CardColor}"
                   BorderColor="{TemplateBinding BorderColor}"
                   CornerRadius="5"
                   HasShadow="True"
                   Padding="8"
                   HorizontalOptions="Center"
                   VerticalOptions="Center">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="75" />
                        <RowDefinition Height="4" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="75" />
                        <ColumnDefinition Width="200" />
                    </Grid.ColumnDefinitions>
                    <Frame IsClippedToBounds="True"
                           BorderColor="{TemplateBinding BorderColor}"
                           BackgroundColor="{TemplateBinding IconBackgroundColor}"
                           CornerRadius="38"
                           HeightRequest="60"
                           WidthRequest="60"
                           HorizontalOptions="Center"
                           VerticalOptions="Center">
                        <Image Source="{TemplateBinding IconImageSource}"
                               Margin="-20"
                               WidthRequest="100"
                               HeightRequest="100"
                               Aspect="AspectFill" />
                    </Frame>
                    <Label Grid.Column="1"
                           Text="{TemplateBinding CardTitle}"
                           FontAttributes="Bold"
                           FontSize="Large"
                           VerticalTextAlignment="Center"
                           HorizontalTextAlignment="Start" />
                    <BoxView Grid.Row="1"
                             Grid.ColumnSpan="2"
                             BackgroundColor="{TemplateBinding BorderColor}"
                             HeightRequest="2"
                             HorizontalOptions="Fill" />
                    <Label Grid.Row="2"
                           Grid.ColumnSpan="2"
                           Text="{TemplateBinding CardDescription}"
                           VerticalTextAlignment="Start"
                           VerticalOptions="Fill"
                           HorizontalOptions="Fill" />
                </Grid>
            </Frame>
        </ControlTemplate>
    </ContentPage.Resources>
    ...
</ContentPage>

The TemplateBinding markup extension resolves binding expressions against each CardView object’s properties in this example. The CardViewControlTemplate is applied to the three CardView objects in the following screenshots:

Passing Parameter with TemplateBinding

Conclusion

In this blog, we have deeply discussed the concepts of Creating a Control template, consuming a Control template, and Passing Parameters with TemplateBinding. This will help you comprehend the usage of controls in various scenarios.

Technocrat and entrepreneur of a reputed esteemed PowerPoint Add-in Development Company with years of experience in building large-scale enterprise web, cloud, and mobile applications using the latest technologies like ASP.NET, CORE, .NET MVC, Angular, and Blockchain. Keen interest in addressing business problems using the latest technologies and helping organizations achieve goals.

The post Explain Controls Template in Xamarin Forms appeared first on Tech Web Space.

]]>