Home > Net >  WPF binding shows the viewModel (using MVVM pattern) nested in the content
WPF binding shows the viewModel (using MVVM pattern) nested in the content

Time:11-28

I just contact with WPF, rookie a, a great god give advice or comments of all stripes:
Background the corresponding code:
Public CurriculumsView ()
{
InitializeComponent ();
The viewModel=new MainWindowViewModel ();
}
The front desk corresponding code:


DisplayMemberBinding="{Binding Path=type}"
The Header="classification"/& gt;
DisplayMemberBinding="{Binding Path=content}"
The Header="content"/& gt;


The type and the content is contained in the mainViewModel CurriculumViewModel entities in the class attribute of Curriculum

CodePudding user response:

Don't you write a listview binding, at the front desk binding & lt; ListView. View itemssource="{Binding viewModel}" & gt;
Or binding in the background, now at the front desk of a name for the Listview & lt; ListView. View name="lv" & gt; And then in the background of public CurriculumsView ()
{
InitializeComponent ();
The viewModel=new MainWindowViewModel ();
}
Add lv. Itemssource=viewModel that effect is
{
InitializeComponent ();
The viewModel=new MainWindowViewModel ();
Lv. Itemssource=viewModel
}

Hope to adopt

CodePudding user response:

Sorry, forgot to paste the binding, before I have binding, so you say is not a problem now I don't know, but still thank you,
Public CurriculumsView ()
{
InitializeComponent ();
The viewModel=new MainWindowViewModel ();
Enclosing DataContext=viewModel;
}

CodePudding user response:

No great god passing? From the top

CodePudding user response:

In the ListView ItemsSource="{Binding}"

CodePudding user response:

The ListView. Itemssource you bound
  •  Tags:  
  • C#
  • Related