SearchBar.IsEnabled binding are not updated when property changed in Xamarin.Forms -



SearchBar.IsEnabled binding are not updated when property changed in Xamarin.Forms -

i want disable searchbar whenever viewmodel busy. , have next xaml view (part of view):

class="lang-xml prettyprint-override"><searchbar x:name="searchbar" textchanged="onsearchquerychanged" grid.row="0" isenabled="{binding isbusy}"/> <activityindicator x:name="progress" isrunning="{binding isbusy}" isvisible="{binding isbusy}"/>

both elements bound the same property searchbar stays disabled when viewmodel raise isbusy = false. same time progress becomes hidden.

what wrong here?

what want set searchbar.isenabled property true when view model isbusy property false, , vice versa.

what you're doing right now, disabling (setting isenabled false) search bar when vie model no longer busy (isbusy false).

you need converter this, 1 returns true false, , false true:

class="lang-cs prettyprint-override">public class notconverter:ivalueconverter { public object convert (object value, type targettype, object parameter, system.globalization.cultureinfo culture) { if (value.gettype () == typeof(bool)) homecoming !((bool)value); homecoming value; } public object convertback (object value, type targettype, object parameter, system.globalization.cultureinfo culture) { throw new notimplementedexception (); } }

in order utilize in binding in xaml, let's include instance of resource in container wrapping xaml snippet (let's assume it's contentpage), , can reference converter in {binding} markup extension:

class="lang-xml prettyprint-override"><contentpage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:yournamespace;assembly=yourassemblyname"> <contentpage.resources> <resourcedictionary> <local:notconverter x:key="notconverter"/> </resourcedictionary> </contentpage.resources> <contentpage.content> <stacklayout orientation="vertical"> <searchbar x:name="searchbar" textchanged="onsearchquerychanged" grid.row="0" isenabled="{binding isbusy, converter={staticresource notconverter}}"/> <activityindicator x:name="progress" isrunning="{binding isbusy}" isvisible="{binding isbusy}"/> </stacklayout> </contentpage.content> </contentpage>

data-binding xamarin searchbar xamarin.forms

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -