Weird behaviour with advanced Binding

MulflarMulflar ESUniversity ✭✭

Hi

Hi have a singleton clase who has this properties:

private string mensaje;
    private bool isDownloading;
    private string progress;

    #region BINDING PROPERTIES
    public string Mensaje
    {
        get
        {
            return mensaje;
        }
        set
        {
            mensaje = value;
            RaisePropertyChanged(() => Mensaje);
        }
    }

    public bool IsDownloading
    {
        get
        {
            return isDownloading;
        }
        set
        {
            isDownloading = value;
            RaisePropertyChanged(() => IsDownloading);
        }
    }

    public string ProgressValue
    {
        get
        {
            return progress;
        }
        set
        {
            progress = value;
            RaisePropertyChanged(() => ProgressValue);
        }
    }

    #endregion

I have a view who uses this singleton in a way like this

<Grid
            Grid.Row="4"
            Grid.ColumnSpan="2"
            Opacity="{Binding Opacity}"
            IsEnabled="{Binding IsOnline}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Label Grid.Row="0"
                   HorizontalOptions="StartAndExpand"
                   VerticalOptions="Center"
                   FontSize="Small"
                   Text="{Binding Mensaje, Source={x:Static helpers:DescargaOffline.Current}}"
                   IsVisible="{Binding ISDownloading, Source={x:Static helpers:DescargaOffline.Current}}"/>

    <!-- PROGRESS-->
            <!--<ProgressBar Grid.Row="1" Scale="5"
                         IsVisible="True"
                         IsEnabled="True"
                         Progress="{Binding ProgressValue, Source={x:Static helpers:DescargaOffline.Current}}"/>-->
            <!-- INDICATOR -->
            <ActivityIndicator
                Grid.Row="1"    
                HeightRequest="100"
                IsRunning="{Binding ISDownloading, Source={x:Static helpers:DescargaOffline.Current}}"
                IsVisible="{Binding ISDownloading, Source={x:Static helpers:DescargaOffline.Current}}"
                VerticalOptions="Center"
                HorizontalOptions="EndAndExpand"/>

            <Button        
                Grid.Row="2"
                HorizontalOptions="FillAndExpand"
                Command="{Binding DoDownloadCommand, Source={x:Static helpers:DescargaOffline.Current}}"                    
                Text="DESCARGAR OFFLINE"                    
                Style="{StaticResource DefaultActionButton}"/>
            <StackLayout  Grid.Row="3"
                          Margin="0,0,0,20"
                          Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
                <Label Text="ÚLTIMA DESCARGA " FontSize="Small"/>
                <Label Text="XX/XX/XXXX" FontSize="Small"/>
            </StackLayout>      
        </Grid>

In the singleton I start a big download process who moves from diferent functions. At the start of the launch I do IsDownloading = true and in the middle of the process I change the Mensaje value and the ProgressValue.

All works ok, except the progress bar or the activity indicator.
In the case of the progress bar the bar is showed but never changes. I have a function who changes the ProgressValue like this:

     private void ProgressCalculator(int current, int max)
    {
        double val = (double)(current + 1) / (double)max;
        ProgressValue = val.ToString().Replace('.', ',');
    }

In the case of the activity indicator it never becomes visible.

Best Answer

  • MulflarMulflar ES ✭✭
    Accepted Answer

    Ok... I solved at least the problem with the ProgressBar ... it was a problem with the android style colors, the color for the filled bar was the same than for the empty bar.

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    edited December 2017

    Your ProgressValue is a string. A ProgressBar value is Decimal

                <ProgressBar HorizontalOptions="CenterAndExpand"
                             VerticalOptions="End"
                             WidthRequest="100"
                             Margin="20,0,20,0"
                             Scale="5"
                             Progress="{Binding App.StartupProgress}">
    
            #region StartupProgress (decimal)
            private decimal _StartupProgress;
            public decimal StartupProgress
            {
                get
                {
                    return _StartupProgress;
                }
    
                set
                {
                    if (_StartupProgress == value) return;
                    _StartupProgress = value;
                    OnPropertyChanged();
                }
            }
            #endregion StartupProgress  (decimal)
    

    The ActivityIndicator in Xamarin is a bit a of a mess and confusing. IsEnabled and IsRunning and IsVisible basically all do the same thing and are strangely tied together and screw each other up. Don't try to manage all of those.
    Don't change IsVisible... Don't change IsEnabled. Leave them both true.
    Just change IsRunning. After all, an ActivityIndicator that isn't running also has nothing to display and therefore is not visible. There is no interaction with an ActivityIndicator so IsEnabled has no purpose.

  • MulflarMulflar ESUniversity ✭✭

    @ClintStLaurent said:
    Your ProgressValue is a string. A ProgressBar value is Decimal

    I firstly used in double but I read a comment who says 0.0 gives problem and 0,0 no so I moved to string.
    Changed to decimal and keep not filling.

    The ActivityIndicator in Xamarin is a bit a of a mess and confusing. IsEnabled and IsRunning and IsVisible basically all do the same thing and are strangely tied together and screw each other up. Don't try to manage all of those.
    Don't change IsVisible... Don't change IsEnabled. Leave them both true.
    Just change IsRunning. After all, an ActivityIndicator that isn't running also has nothing to display and therefore is not visible. There is no interaction with an ActivityIndicator so IsEnabled has no purpose.

    Changed to

    Still not running :-S

  • MulflarMulflar ESUniversity ✭✭
    Accepted Answer

    Ok... I solved at least the problem with the ProgressBar ... it was a problem with the android style colors, the color for the filled bar was the same than for the empty bar.

Sign In or Register to comment.