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.
Model:
public class LoginModel
{
public string username { get; set; }
public string usercode { get; set; }
}
view model:
public LoginModel LoginModel1
{
get { return userAccounts; }
set
{
userAccounts = value;
OnPropertyChanged();
//RaisePropertyChanged();

        }

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

    public LoginVM(Page page)
    {
        this.page = page;
    }

view:



<Entry.Effects>

</Entry.Effects>


Posts

  • 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 12
    **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:
    2.
    3.
    4.
    5. <Entry.Effects>
    6.
    7. </Entry.Effects>
    8.
    9.
    10.

    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.

Sign In or Register to comment.