Understanding How to Express Button Dynamically in xaml

Asked 1 years ago, Updated 1 years ago, 123 views

Ask about the dynamic display of the button you tapped after tapping Button.
Assume that an xaml file has the following Button tags:

<Button 
    Clicked="TheButtonTapped"
    Image="sample.png"
    WidthRequest="256"
    HeightRequest="256"
    Opacity="0.0"
    VerticalOptions="Center"/>

When you run the button tap ("TheButtonTapped") you can click this button as follows:
I want to show it dynamically.

JQuery has an example implementation, so it's easy to imagine, but the C# version is
I'm in trouble because I couldn't find it.
If you know anyone, please let me know.

c# xaml xamarin

2022-09-30 16:28

1 Answers

If you're looking for animation, Xamarin.Forms has animation features, so you can do it with them.

<Button 
    Text = "Button 1"
    Clicked="Button1_Clicked"/>

<Button 
    x —Name="Button 2"
    Text = "Button 2"
    Clicked="Button2_Clicked"/>

To run the desired animation on Button2 when there are two buttons (Button1 and Button2) as shown above and Button1 is pressed:

 volatile bool_button2 Enabled = true;

async void Button1_Clicked (object sender, System.EventArgse)
{
    _button2Enabled=false;
    // Button2.IsEnabled=false; doesn't it look appropriate because the button turns into an inactive color?

    // Animation starts: fadeout over 5 seconds (reduces Opacity from '1.0' to '0.0')
    Button2.Opacity=1.0;
    wait Button 2. FadeTo (0.0, 5000, Easing. Linear);

    _button2Enabled=true;
    // Button2.IsEnabled = true; 
}

void Button2_Clicked (object sender, System.EventArgse)
{
    If(!_button2Enabled)//Button2.Locked with flag if IsEnabled is not available
        return;
}

The button should be locked using Button2.IsEnabled=false, but this may cause the button to change to inactive color, which may cause discomfort in animation.In that case, you must have your own flag and achieve the lock as shown in the code above.


2022-09-30 16:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.