Setting a XAML Icon to show an activity indicator when clicked

Hi,

I have an icon on my app, which when it is clicked, I would like to change it to an activity indicator. It looks as though I should use a Trigger, Event Triggers look good, but as my image is declared in XAML, I am not sure quite how it would fit together?

At the moment, I have this in XAML:

      <Button x:Name="NewDeviceButton" 
                Image="glyphish_31_circle_x.png" 
                HorizontalOptions="End"
                VerticalOptions="EndAndExpand" />

When it is clicked, I would like to show this, for a set amount of time, then trigger some C# functionality:

<ActivityIndicator Color="Black" IsRunning="true" />

How would I best structure this?

Answers

  • MathiesonSterlingMathiesonSterling USMember
    edited September 2015

    If you're using MVVM, it's very simply to have a field for whether or not you're running. In that case you'd see something like

    <ActivityIndicator Color="Black" IsRunning="{Binding IsBusy}" />

    Your code behind would then use a command, something like
    `public bool IsBusy{get{return GetValue();}set{SetValue(value);}}
    public ICommand NewDeviceCommand{get{return new Command(NewDevice);}}

    public async void NewDevice(){
    IsBusy = true;
    await DoMyLongRunningTask();
    IsBusy = false;
    }`

    This will not give you a standard time - instead you'll do your activity only while you're truly busy.

  • GeorgeEdwardsGeorgeEdwards GBMember ✭✭

    Thanks Mathieson, and how would I best structure the other button icon, to disappear when this is activated, ideally, so they are on top of each other?

Sign In or Register to comment.