locked
passing variable into a class when i go to the next page RRS feed

  • Question

  • User390299 posted

    i have and object called registerUser it contains an email for the user and a id token. when the get it its on the login screen and i need to pass it to the next activity. but the next activity is a carousel view of two other pages so i cant just pass it to the next page. ill show code below. pls help

    so this is what happens when a user is logged in

        async private void loginUser_Clicked(object sender, EventArgs e)
        {
            Boolean returnToken = true;
            try
            {
    
                string jsonlogin = await apiRequestHelper.RequestLoginUserAsync((LinputEmail.Text).ToString(), (LinputPassword.Text).ToString(), returnToken);       
                var response = jsonHelper.deserializeLoginResponse(jsonlogin);
                await Navigation.PushAsync(new InAppView());
            }
            catch(Exception err)
            {
                string response = firebaseRestApiHelper.LoginCheck((err).ToString());
                await DisplayAlert("Alert", response, "OK");
            }
        }
    

    response is the object i need to pass it contains

       public class GlobalId
    {
        public  string IdToken { get; set;}
        public string email { get; set; }
        public string refreshtoken { get; set; }
        public string expiresIn { get; set; }
        public string localId { get; set; }
        public bool registered { get; set; }
    } 
    

    and i cant pass it to the next activity because its a carousel view and has no code.

    this is in app view xamal and cs just to prove they have nothing but boilerplate code

        <?xml version="1.0" encoding="UTF-8"?>
        <CarouselPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:local="clr-namespace:Kula"
             mc:Ignorable="d"
             x:Class="Kula.InAppView">
       <local:SocialFeed/>
       <local:Profile/>
    
     </CarouselPage>
    
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
    
      using Xamarin.Forms;
      using Xamarin.Forms.Xaml;
    
      namespace Kula
      {
       [XamlCompilation(XamlCompilationOptions.Compile)]
      public partial class InAppView : CarouselPage
      {
        public InAppView()
        {
            InitializeComponent();
        }
       }
      }
    

    here is the social feed cs

      using Kula.Models;
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using Xamarin.Forms;
      using Xamarin.Forms.Xaml;
    

    namespace Kula { [XamlCompilation(XamlCompilationOptions.Compile)]

     public partial class SocialFeed : ContentPage
     {
    
        public SocialFeed()
        {
            InitializeComponent();
    
    
    
        }
       }
       }
    

    social feed xamal

        <?xml version="1.0" encoding="utf-8" ?>
        <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:vm="clr-namespace:Kula.ViewModels"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"            
             mc:Ignorable="d"
             x:Class="Kula.SocialFeed"
             BackgroundColor="White"
             Title="Social Feed Collection View"
    
             >
       <ContentPage.BindingContext>
         <vm:SocialFeedTileViewModel/>
    
      </ContentPage.BindingContext>
      <ContentPage.Content>
    
            <CollectionView ItemsSource="{Binding SocialFeedTiles}">
                <CollectionView.ItemTemplate>
                    <DataTemplate>
    
                    <StackLayout Padding="0,0,0,5">
                        <Frame  Padding="0" HeightRequest="50" CornerRadius="10"    HasShadow="False"  >
                            <Grid Padding="0" ColumnSpacing="5" Margin="0,3,0,0">
    
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width=".15*"/>
                                    <ColumnDefinition Width=".75*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height=".95*"/>
                                    <RowDefinition Height=".05*"/>
    
                                </Grid.RowDefinitions>
    
                                <Image Grid.Column="0" Source="{Binding ProfilePhotoUrl} " Grid.Row="0" Aspect="AspectFit"/>
    
                                <StackLayout VerticalOptions="Center"  Grid.Column="1" Grid.Row="0">
                                    <Label Text="{Binding Username}" FontSize="10" />
                                  <Label Text="{Binding FullName}" FontSize="15"  />
                                </StackLayout>
                                <Frame Grid.ColumnSpan="2"
                                       Grid.Row="1" 
                                       BackgroundColor="#FF6F00" 
                                       HasShadow="False"
                                       CornerRadius=".025" 
                                       Margin="7,.05,7,0"
                                       Padding="0">
    
                                </Frame>
                            </Grid>
                        </Frame>
                        <StackLayout x:Name="post" >
                            <Image Source="{Binding PostUrl}" Aspect="AspectFill" />
                        </StackLayout>
                        <Frame  Padding="0" HeightRequest="55" CornerRadius="10" HasShadow="False"  >
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width=".155*"/>
                                    <ColumnDefinition Width=".155*"/>
                                    <ColumnDefinition Width=".155*"/>
                                    <ColumnDefinition Width=".535*"/>
                                </Grid.ColumnDefinitions>
    
                                <Grid Grid.Column="0" Padding="0" RowSpacing="0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height=".7*"/>
                                        <RowDefinition Height=".25*"/>
                                        <RowDefinition Height=".05*"/>
                                    </Grid.RowDefinitions>
                                    <ImageButton Grid.Row="0"  />
                                    <Label  Text="likes" FontSize="Micro" Grid.Row="1" HorizontalOptions="CenterAndExpand" />
                                    <BoxView  Grid.Row="2" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
                                </Grid>
                                <Grid Grid.Column="1" RowSpacing="0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height=".7*"/>
                                        <RowDefinition Height=".25*"/>
                                        <RowDefinition Height=".05*"/>
                                    </Grid.RowDefinitions>
                                    <ImageButton Grid.Row="0" />
                                    <Label Text="comments" FontSize="Micro" Grid.Row="1" HorizontalOptions="CenterAndExpand" />
                                    <BoxView Grid.Row="2" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
    
    
                                </Grid>
                                <Grid Grid.Column="2" RowSpacing="0" >
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height=".7*"/>
                                        <RowDefinition Height=".25*"/>
                                        <RowDefinition Height=".05*"/>
                                    </Grid.RowDefinitions>
                                    <ImageButton Grid.Row="0" />
                                    <Label Text="share" FontSize="Micro" Grid.Row="1" HorizontalOptions="CenterAndExpand" />
                                    <BoxView Grid.Row="2" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
    
                                </Grid>
    
                            </Grid>
                        </Frame>
                    </StackLayout>
    
    
                    <!--<Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="100"/>
                                <ColumnDefinition Width="*"/>
    
                            </Grid.ColumnDefinitions>
                            <Image Source="{Binding ProfilePhotoUrl}" Grid.Column="0"/>
                            <StackLayout Orientation="Vertical" Grid.Column="1">
                                <Label Text="{Binding Username}" FontSize="Title"/>
                                <Label Text="{Binding FullName}" FontSize="Subtitle"/>
                            </StackLayout>
                        </Grid>-->
    
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
    
    
       </ContentPage.Content>
       </ContentPage>
    

    as you can see they are only populated through binding classes and these binding classes are where i need to get the object

    binding classes below
    
     SERVICE(hardcoded values but will be loaded using the id in globalid)
    
     using Kula.Models;
     using System;
     using System.Collections.Generic;
     using System.Text;
    
     namespace Kula.Services
    {
      public class SocialFeedService
     {
    
        public List<SocialFeedTile> GetSocialFeedTiles() 
        {
            return new List<SocialFeedTile>()
            {
                new SocialFeedTile(){ Username="thelocater", FullName="Tiernan morgan", ProfilePhotoUrl="circleimage1.png", PostUrl="post1.jpg"},
                new SocialFeedTile(){ Username="thepartydude", FullName="Guy Fieri", ProfilePhotoUrl="circleimage2.png", PostUrl="post2.jpg"},
                new SocialFeedTile(){ Username="thatkid", FullName="Blaine Morgan", ProfilePhotoUrl="circleimage3.png", PostUrl="post3.jpg"},
                new SocialFeedTile(){ Username="fiestachick", FullName="aubery plaza", ProfilePhotoUrl="circleimage4.png", PostUrl="post4.jpg"},
                new SocialFeedTile(){ Username="ballonbruh", FullName="jack boredom", ProfilePhotoUrl="circleimage5.png", PostUrl="post5.jpg"},
            };    
         }
    
        }
       }
    

    VIEWMODEL

     using Kula.Models;
     using Kula.Services;
     using System.Collections.Generic;
     using System.Text;
    
     namespace Kula.ViewModels
     {
     public class SocialFeedTileViewModel
     {
        public List<SocialFeedTile> SocialFeedTiles { get; set; }
    
        public SocialFeedTileViewModel()
        {
            SocialFeedTiles = new SocialFeedService().GetSocialFeedTiles();
    
        }
      }
     }
    

    Sunday, November 24, 2019 10:04 AM

All replies

  • User380187 posted

    @theConfusedOne Hi , you can define the needed paramater in Next Page .

    Monday, November 25, 2019 9:53 AM
  • User390299 posted

    @JuniorJiang said: @theConfusedOne Hi , you can define the needed paramater in Next Page .

    with a carousal view? because i need to get this parameter to three pages at once technically

    Monday, November 25, 2019 10:03 AM
  • User380187 posted

    Hi @theConfusedOne , u can have a try with a custom carousal view with Bindable needed Properties , then can be used in each view . Or u can show the the code of carousal view , and I will check it .

    Tuesday, November 26, 2019 4:14 AM