Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Triggering binding in other binding

FMGNoobFMGNoob Member ✭✭
edited November 2019 in Xamarin.Forms

Hi guys , I have a picker and button .I want to set button visibilty after picker selected. Seems like OnSelectedChanged action of picker can not be bind to a command . i have already binding for SelectedItem property so i thought i can use this for make button visible. It is working but there is a problem : Button visibilty doesnt changing after picker first selection time. After 1. selection if i select other thing on picker it is changing.

This is my code :
// MVVM part

public bool IsLevelSelected {
        get { return _isLevelSelected; }
        set
        {
            _isLevelSelected = value;
            OnPropertyChanged(nameof(IsLevelSelected));
        }

             }
    public string SelectedLevel
    {
        get
        {
            return _selectedLevel;
        }
        set
        {
            IsLevelSelected = true;
            _selectedLevel = value;
            OnPropertyChanged(nameof(SelectedLevel));

        }
    }

//XAML

<Picker x:Name="picker" Title="Seviye seçiniz" FontAttributes="Bold" FontSize="Large" Margin="0,50,0,0"
SelectedItem="{Binding SelectedLevel}" HorizontalOptions=" >
<Button Text="{Binding SelectedLevel,StringFormat='{0}. Leveli Başlat'}" d:Text="1.ci Leveli Başlat"
Command="{Binding StartGame}"
HeightRequest="100" Margin="20,40,20,20"
BorderWidth="5" BackgroundColor="DarkKhaki"
IsVisible="{Binding IsLevelSelected}"
CornerRadius="25" CommandParameter="{Binding SelectedLevel}"

Best Answers

  • FMGNoobFMGNoob Member ✭✭
    Accepted Answer

    @ColeX said:
    Try to update Xamarin.Forms package to the latest in Forms and specific project to see if problem persists.

    PS : I test on XF 4.2.0.709249 .

    I updated **every ** package installed , it worked. THANK YOU

Answers

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    So your problem is that the Button Text binding isn't updating when you change the Picker SelectedItem? Or are you expecting the IsLevelSelected property to change to false again at some point?

  • FMGNoobFMGNoob Member ✭✭

    @JoeManke said:
    So your problem is that the Button Text binding isn't updating when you change the Picker SelectedItem? Or are you expecting the IsLevelSelected property to change to false again at some point?

    I want To set "IsLevelSelected" as "true" when a level selected from picker.

  • FMGNoobFMGNoob Member ✭✭

    https://files.fm/u/y4huab24

    This is screen record of problem . I want to make it visible at first selection.

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    Strange. If you put a breakpoint in the SelectedLevel setter, is it hit the first time?

  • FMGNoobFMGNoob Member ✭✭

    Yes it does.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited November 2019

    Same code works perfectly on my side , what's the Forms version did you test on ?

  • FMGNoobFMGNoob Member ✭✭

    @ColeX said:
    Same code works perfectly on my side , what's the Forms version did you test on ?

    <PackageReference Include="Xamarin.Forms" Version="4.1.0.555618" />
    <PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
    
  • FMGNoobFMGNoob Member ✭✭
    Accepted Answer

    @ColeX said:
    Try to update Xamarin.Forms package to the latest in Forms and specific project to see if problem persists.

    PS : I test on XF 4.2.0.709249 .

    I updated **every ** package installed , it worked. THANK YOU

Sign In or Register to comment.