Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Bug : Switching IsVisible on a button does not redraw the button

$
0
0

Hi,

I have found something weird, when switching IsVisibility of several button embbedded in a stacklayout, using a viewModel (Commands and bindings) the buttons does not always redraws themself (on iOS, did not try on Android).

I have tree buttons, if the first is visible the others ar hidden, if I click on the first one, it desepears and the other are shown, if I click on the third one the two last button should despear and the first one should be visible.

Here is my code (Test project attchaed) :

public class App : Application
{
    Button Stop;
    Button Record;
    Button Pause;
    MyViewModel vm;
    public App()
    {
        this.BindingContext = new MyViewModel();
        vm = (MyViewModel)this.BindingContext;
          Record = new Button
        {
            Text = "Record",
        };
          Record.SetBinding<MyViewModel>(Button.IsVisibleProperty, t => t.IsRecording, converter: new InvertBoolenConverter());
         Record.Command = vm.StartRecordingCommand;

        Pause = new Button
        {
            Text = "Pause",
        };
        Pause.SetBinding<MyViewModel>(Button.IsVisibleProperty, t => t.IsRecording);

        Stop = new Button
        {
            Text = "Stop",
        };
        Stop.SetBinding<MyViewModel>(Button.IsVisibleProperty, t => t.IsRecording);
        Stop.Command = vm.StopRecordingCommand;

        StackLayout stack = new StackLayout
        {
            Padding = new Thickness(10,10,10,10),
            BackgroundColor = Color.Red,
            Orientation = StackOrientation.Horizontal,
            VerticalOptions = LayoutOptions.Center,
            Children = {
                Record, 
                Pause,
                Stop
            }
        };

        // The root page of your application
        MainPage = new ContentPage
        {

            Content=new StackLayout
            {
                Children = {
                    stack,

                }
            }
        };
    }

The View Model :

public class MyViewModel : ObservableObject
{

    private bool isRecording;

    public bool IsRecording
    {
        get
        {
            return isRecording;
        }
        private set
        {
            isRecording = value;

                this.NotifyPropertyChanged(() => IsRecording);

        }

    }
    public ICommand StartRecordingCommand
    {
        get
        {
            return new Command(() =>
            {
                IsRecording = true;
            });
        }
    }

    public ICommand StopRecordingCommand
    {
        get
        {
            return new Command(() =>
            {
                IsRecording = false;
            });
        }
    }
}

Viewing all articles
Browse latest Browse all 77050

Trending Articles