Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i am beginner in mvvm concept.so i tried one sample application.it contains two textbox are name and id, one submit button,one label.when i click submit button it combine the two strings from the textbox and display in label.

i can submit the values and in viewmodel the property contain the result.but its not shown in view.why..?

in view contains

XAML
<grid>
   <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding name}"  Height="23"  Margin="9" Name="txtname"  Width="120" />
   <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding id}" Height="23"  Margin="9" Name="txtid"  Width="120" />
   <Button Command="{Binding submit}" Content="submit" Grid.Column="2" Grid.Row="2" Height="23"   Name="btnsubmit"  Width="75" />
   <Label Content="{Binding display}" Grid.Row="3" Height="38" HorizontalAlignment="Left"  Name="lbldisplay"  Width="192" />

   </grid>


view.cs code is

C#
public MainWindow()
       {
           InitializeComponent();
           DataContext = new DemoViewModel();
       }


in my viewmodel contains two .cs file

one is DemoViewModelInotify.cs.in this i write the code for inotifypropertychanged.
another one is DemoViewModel.cs.this contain the property and commands.

C#
namespace mvvmdemonixon.ViewModel
   {
   public  class DemoViewModel :DemoViewModelInotify
   {
     public ICommand submit { get; set; }

     public string name { get; set; }
     public string display { get; set; }
     public int id{get;set;}
     public DemoModel model { get; set; }
     public DemoViewModel()
     {

         submit = new DelegateCommand<object>(this.add);

     }

     public void add(object paramter)
     {
       string a=  mvvmdemonixon.Model.DemoModel.addstring(name, id);
       display = a;
     }

   }
   }

my model contains

C#
namespace mvvmdemonixon.Model
   {
   public  class DemoModel
   {
      public static string addstring(string name1, int no1)
      {
          string display = "The Student Name Is " + name1 + "and Id Is" + no1 + ".";
          return display;
      }

   }
   }


in my app.xaml.cs

C#
private void OnStartup(object sender, StartupEventArgs e)
      {
          mvvmdemonixon.MainWindow view = new MainWindow();
          view.DataContext = new mvvmdemonixon.ViewModel.DemoViewModel();
          view.Show();
      }

in my app xaml

XAML
<Application x:Class="mvvmdemonixon.App"
   Startup="OnStartup">
   </Application>



advance thanks..
Posted

1 solution

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