Posts

Showing posts from August, 2019

Read Data from Json file

 Step 1  Past json format to text file save as .json Step 2 add file in to pcl Step 3 Right click the file and Select properties Step 4 Change Build action to Embedded Resource Step 5   Add this method to ViewModel private void GetJsonData()         {             try             {                 var _tempdata = new ResponseData();                 string jsonFileName = "gold_sample_response.json";                 var assembly = typeof(CurrentViewModelname).GetTypeInfo().Assembly;                 Stream stream = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{jsonFileName}");                 using (var reader = new System.IO.StreamReader(stream))   ...

Alter List Item while Binding

Step 1               add needed paramenter to required list step 2              Use that paramenter to bind in list item source --------------------------        if (result.listdata!= null)                             {                                                                 List<TrackList> objlist = new List<TrackList>();                                 foreach (var item in result.listdata)                                 {               ...

Listview SelectedItem in MVVM

Create Helper class named ListViewBehaviours ------------------------------- ListViewBehaviours.cs  public class ListViewBehaviours : Behavior<ListView> { public static readonly BindableProperty CommandProperty = BindableProperty.Create( propertyName: "Command", returnType: typeof(ICommand), declaringType: typeof (ListViewBehaviours)); public ICommand Command { get { return (ICommand)GetValue(CommandProperty); } set { SetValue(CommandProperty, value); } } protected override void OnAttachedTo(ListView bindable) { base.OnAttachedTo(bindable); bindable.ItemSelected += Bindable_ItemSelected; bindable.BindingContextChanged += Bindable_BindingContextChanged; } private void Bindable_BindingContextChanged(object sender, EventArgs e) { var lv = sender as ListView; BindingContext = lv?.BindingContext; } private void Bindable_ItemSelected(object sender, SelectedItemChangedEv...

Button click event with current object from listview having button

 XAML <StackLayout.GestureRecognizers>               <TapGestureRecognizer Command="{Binding Path=BindingContext.OnReadMoreClicked, Source={x:Reference Page}}" CommandParameter="{Binding .}" />  </StackLayout.GestureRecognizers> ----------------------------------- In ViewModel   private Command<object> _onReadMoreClicked;         public Command<object> OnReadMoreClicked         {             get             {return _onReadMoreClicked ?? (_onReadMoreClicked = new Command<object>((currentObject) =>                 GetDetailsforRead(currentObject)                 ));             }         }