Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.I'm trying to learn mvvm.So I did research.And I wanted to start with a simple example.But I had problems with the bind.How can I help you with this?But dont write ModelView.cs.How to bind modelview.

What I have tried:

Login.xmal

<Window x:Class="Login.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Login"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Label x:Name="lblUsername" Content="Username" HorizontalAlignment="Left" Margin="45,57,0,0" VerticalAlignment="Top"/>
        <Label x:Name="lblPassword" Content="Password" HorizontalAlignment="Left" Margin="48,104,0,0" VerticalAlignment="Top"/>
        <TextBox x:Name="txtUsername" Text="{Binding Textbox1Input, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
             HorizontalAlignment="Left" Height="23" Margin="128,60,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBox x:Name="txtPassword" Text="{Binding Textbox2Input, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
             HorizontalAlignment="Left" Height="23" Margin="128,108,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Button x:Name="btnSubmit" Content="Submit" HorizontalAlignment="Left" Margin="118,175,0,0" VerticalAlignment="Top" Width="75"
            Command="{Binding SubmitLoginButton}"
            />
    </Grid>
</Window>


But not LoginVM.cs not write and Model.cs is include this property
Database Name: [Person].[dbo].[PersonLogin]

Property:
[Id]
,[Username]
,[Password]
Posted
Updated 10-Mar-19 9:17am
v2
Comments
Afzaal Ahmad Zeeshan 10-Mar-19 17:54pm    
And the problem is?

Are you facing an exception, please share that. Also, what is the structure for this Model class?
Graeme_Grant 11-Mar-19 0:12am    
Where have you set the DataContext for the form?
[no name] 11-Mar-19 0:41am    
Yep, also betting on DataContext.
AnkushK1 12-Mar-19 7:19am    
You need to provide the data context where your view should look for. Also make sure that your model implements INotifyPropertyChanged interface

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900