This is a migrated thread and some comments may be shown as answers.

Binding the "IsOpen" property?

3 Answers 256 Views
SideDrawer
This is a migrated thread and some comments may be shown as answers.
Michel
Top achievements
Rank 1
Michel asked on 16 Mar 2017, 08:17 AM

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....

 

3 Answers, 1 is accepted

Sort by
0
Michel
Top achievements
Rank 1
answered on 16 Mar 2017, 08:24 AM

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....

0
Lance | Manager Technical Support
Telerik team
answered on 16 Mar 2017, 04:38 PM
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
0
Michel
Top achievements
Rank 1
answered on 28 Mar 2017, 02:51 PM

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}" />

Tags
SideDrawer
Asked by
Michel
Top achievements
Rank 1
Answers by
Michel
Top achievements
Rank 1
Lance | Manager Technical Support
Telerik team
Share this question
or