Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Changing IsBusy not working from Code Behind

$
0
0

I would like to know why is the IsBusy flag has no effect when called from the code behind. If the IsBusy is set in the viewmodel code then it works.

// PageOne.xaml
<?xml version="1.0" encoding="utf-8" ?>

    <ContentPage.Content>
    <StackLayout > 
        <Frame  Padding="0,0,0,0"  >
            <FlexLayout " Direction="Column" AlignItems="Center" JustifyContent="SpaceEvenly" >

                <StackLayout>
                        <StackLayout  IsVisible="{Binding IsBusy}">
                            <ActivityIndicator Color="Blue" IsRunning="{Binding IsBusy}"/>
                            <Label  HorizontalOptions="Center" FontSize="Medium" Text="{Binding BusyMessage}"  />
                        </StackLayout>
                        <Button Text="Done"  x:Name="PageOneDone" 
                        WidthRequest="120"  BorderRadius="60" VerticalOptions="Center" 
                        StyleClass="primary" HorizontalOptions="Center"
                        Clicked="OnButtonClicked" />
                </StackLayout>
        </FlexLayout>
        </Frame>

        </StackLayout>
    </ContentPage.Content>
</ContentPage>

//PageOne.xaml.cs

        namespace myApp.View
        {
            [XamlCompilation(XamlCompilationOptions.Compile)]
            public partial class PageOne : ContentPage
            {
                PageOneViewModel _modelview;
                public PageOne()
                {

               BindingContext = _modelview = new PageOneViewModel();

                    InitializeComponent();
                }

                private async void OnButtonClicked(object sender, ClickedEventArgs click)
                {
                _modelview.IsBusy = true;
                }
        }

//PageOneViewModel.cs

    namespace myApp.ViewModel
    {
        class PageOneViewModel: ViewModelBase
        {

        }
    }

//ViewModelBase.cs

            namespace myApp.ViewModel.Base
            {
                public abstract class ViewModelBase : INotifyPropertyChanged
                {
                    private bool _isBusy;
                    private string _busymessage = "Busy";

                    public bool IsBusy
                    {
                        get
                        {
                            return _isBusy;
                        }

                        set
                        {
                            _isBusy = value;
                            RaisePropertyChanged(nameof(IsBusy));
                        }
                    }

                    public string BusyMessage
                    {
                        get
                        {
                            return _busymessage;
                        }

                        set
                        {
                            _busymessage = value;
                            RaisePropertyChanged(nameof(BusyMessage));
                        }
                    }


                    public event PropertyChangedEventHandler PropertyChanged;

                    public void RaisePropertyChanged([CallerMemberName]string propertyName = "")
                    {
                        var handler = PropertyChanged;
                        if (handler != null)
                            handler(this, new PropertyChangedEventArgs(propertyName));
                    }
                }
            }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>