Forum Xamarin.Forms

I need to bind two entrys from database but couldn't bind to view model to view

i have two entrys in my view i need to bind the two entries from view model to view.
public class LoginModel
public string username { get; set; }
public string usercode { get; set; }
view model:
public LoginModel LoginModel1
get { return userAccounts; }
userAccounts = value;


    Page page;
    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

    public LoginVM(Page page)
    { = page;





  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @Murali10111421 You will have to properly format your code so that we understand it easily. Show us full XAML, specially showing where the Entry views are situated and how they are used.

  • Murali10111421Murali10111421 Member ✭✭
    edited February 2019
    **1. MY VIEW CODE:
    2. <StackLayout  Margin="30,50,30,0" VerticalOptions="StartAndExpand">
    3.             <Entry x:Name="Username" BindingContext="{Binding LoginModel.username,Mode=TwoWay}" TextColor="Black"  Placeholder="Username" />
    4.             <Entry x:Name="Usercode" BindingContext="{Binding LoginModel.usercode,Mode=TwoWay}" TextColor="Black"  IsPassword="True" Placeholder="Usercode">
    5.                 <Entry.Effects>
    6.                     <ef:IShowHidePassEffect />
    7.                 </Entry.Effects>
    8.             </Entry>
    9.             <Button x:Name="BtnLogin"  BackgroundColor="SteelBlue" TextColor="Lavender" Text="Login"  Command="{Binding btnlgn}"  />
    10.         </StackLayout>**
  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @Murali10111421 said:
    1. MY VIEW CODE:
    5. <Entry.Effects>
    7. </Entry.Effects>

    First I have not used this type of Binding syntax. But may be the following changes will help:

    1. Your ViewModel is LoginModel1 and you are using LoginModel. To avoid confusion normally a ViewModel's name is either prefixed or suffixed with VM or viewmodel. Anyway that is up to your preferences.
    2. Secondly, Set the BindingContext of the page to LoginModel1.
    3. Then just use `"{Binding username, Mode=TwoWay}"` or so.

    I don't know if the Binding syntax you used is valid. If it is valid then probably the #1 above should resolve your issue.

  • Murali10111421Murali10111421 Member ✭✭

    Entry x:Name="Username" Text="{Binding username}" TextColor="Black" Placeholder="Username"
    Entry x:Name="Usercode" Text="{Binding usercode}" TextColor="Black" IsPassword="True" Placeholder="Usercode"
    Button x:Name="BtnLogin" Text="{Binding Btntext}" BackgroundColor ="SteelBlue" TextColor="Lavender" Command="{Binding btnlgn}"

    using this way i get my solution Tnq somuch guys

Sign In or Register to comment.