Câu hỏi phỏng vấn Xamarin
Câu hỏi

What are Triggers? How many types of Triggers are available?

Câu trả lời

In Xamarin.Forms, Triggers are a powerful feature that allows developers to declaratively express actions in XAML that are executed when a specified condition is met. Triggers enable you to change the appearance or behavior of controls based on property values, events, or data conditions without writing extensive code-behind logic.

Types of Triggers in Xamarin.Forms

There are four main types of Triggers in Xamarin.Forms:

  1. Property Trigger:

    • Description: Executes when a property on a control is set to a particular value.
    • Example: Changing the background color of an Entry control when it gains focus.
    • Usage:
      xml Copy
      <Entry Placeholder="Enter your name">
          <Entry.Triggers>
              <Trigger TargetType="Entry" Property="IsFocused" Value="True">
                  <Setter Property="BackgroundColor" Value="Yellow" />
              </Trigger>
          </Entry.Triggers>
      </Entry>
    • References: [1][3][4][7]
  2. Data Trigger:

    • Description: Similar to a Property Trigger but uses data binding. It triggers actions based on the value of a bound property.
    • Example: Disabling a button when the text length of an Entry control is zero.
    • Usage:
      xml Copy
      <Button Text="Submit">
          <Button.Triggers>
              <DataTrigger TargetType="Button" Binding="{Binding Text.Length, Source={x:Reference emailEntry}}" Value="0">
                  <Setter Property="IsEnabled" Value="False" />
              </DataTrigger>
          </Button.Triggers>
      </Button>
    • References: [3][4][7]
  3. Event Trigger:

    • Description: Executes user-defined code when an event occurs on the control.
    • Example: Performing an animation when a button is clicked.
    • Usage:
      xml Copy
      <Button Text="Click Me">
          <Button.Triggers>
              <EventTrigger Event="Clicked">
                  <local:ButtonClickTriggerAction />
              </EventTrigger>
          </Button.Triggers>
      </Button>
      csharp Copy
      public class ButtonClickTriggerAction :...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

How to do Xamarin.Android applications work?

senior

How to make iOS native libraries accessible in Xamarin apps?

expert

What is the disadvantage of Xamarin to using for example Objective-C or Java for iOS and Android
separately?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào