Binding the "IsOpen" property?

4 posts, 0 answers
  1. Michel
    Michel avatar
    18 posts
    Member since:
    Oct 2016

    Posted 16 Mar Link to this post

    I am using the mvvm pattern and would like to bind the SideDrawer "IsOpen" property.

    I have created a boolean property that raises property changed event and bind to it. With a button I change this property to the opposite value. Initially I set it to true and when the screen opens the sidedrawer is visible like expected. When I hit the button the bound property is changed but it has no effect on the visibility of the sidedrawer? Also when I close the drawer by sliding it down It does not change the bound property? I would expect that it changes to false when I do this.

    What am I missing here? Is "IsOpen" a bindable property?

    vm (using freshmvvm):

    public bool SettingsVisible

    {     

        get     

           {         

               return _settingsVisible;     

           }     

          set    

         {        

             _settingsVisible = value;

            RaisePropertyChanged("SettingsVisible");

        }

    }

     

    SettingsCommand = new Command(SettingsHit); //bound to button command to show/hide sidedrawer

    public void SettingsHit() {     SettingsVisible = !SettingsVisible; }

     

    xaml:

      <telerikPrimitives:RadSideDrawer x:Name="drawer" DrawerLength="200" DrawerLocation="Bottom" DrawerTransitionType="SlideInOnTop"                                   DrawerTransitionFadeOpacity="0.5" IsOpen="{Binding SettingsVisible}">    

    <telerikPrimitives:RadSideDrawer.MainContent> 

    etc....

     

  2. Michel
    Michel avatar
    18 posts
    Member since:
    Oct 2016

    Posted 16 Mar Link to this post

    while copying the xaml I missed the crucial part. This is how my xaml is:

      <telerikPrimitives:RadSideDrawer x:Name="drawer" DrawerLength="200" DrawerLocation="Bottom" DrawerTransitionType="SlideInOnTop"                                   DrawerTransitionFadeOpacity="0.5" IsOpen="{Binding SettingsVisible}">    

    <telerikPrimitives:RadSideDrawer.MainContent>  

    etc....

  3. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    419 posts

    Posted 16 Mar Link to this post

    Hello Michael,

    IsOpen is indeed a bindable property, thus the problem you're having isn't related to UI for Xamarin directly. From the code you've shared, I cannot see the problem. Is suspect there's a problem with your command, your SettingsVisible binding or your BindingContext. 

    To help you diagnose the issue, I've attached a demo that opens the drawer from a MainContent Button click (do a Rebuild to restore the missing dependencies). The viewmodel code is identical to yours, a bool, a command and a method to toggle the bool.

    If you still can't get it to work, I recommend putting a Debug.WriteLine() in each of your methods (the bool's setter. the command and the method) to make sure they're being hit.

    Good luck!

    Regards,
    Lance | Tech Support Engineer, Sr.
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  4. Michel
    Michel avatar
    18 posts
    Member since:
    Oct 2016

    Posted 28 Mar Link to this post

    Hi Lance,

    I found the cause of this problem. Xamarin bindings are oneway by default. After I added ",Mode=TwoWay" to the binding in xaml it all works fine.

    So in your example it should be:

    <Button Text="Toggle Side Drawer"         Command="{Binding ToggleDrawerCommand, Mode=TwoWay}" />

Back to Top