wpf learning notes and mvvmlight

vs2015
mvvmlight (NuGet download the latest version)

First, forced to close

In my program ran a new thread
Thread.Start ()

Wpf window is closed, the program did not finish the thread, the thread continues to run in the background and
then join the main form of .cs file

protected override void OnClosed(EventArgs e)
{
 base.OnClosed(e);
 Environment.Exit(0);
}

Second, the project into question and mvvmlight

After adding mvvmlight in use to mvvmlight type of work in
the project will be more of a ViewModel folder
there are two documents:
MainViewModel.cs
ViewModelLocator.cs

The original App.xaml in a few lines will be more stuff:

<Application x:Class="WpfApp2.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApp2" StartupUri="View/WelcomeView.xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d1p1:Ignorable="d" xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
  <Application.Resources>
    <ResourceDictionary>
      <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="clr-namespace:WpfApp2.ViewModel" />
    </ResourceDictionary>
  </Application.Resources>
</Application>

I.e. the code above

<ResourceDictionary>

Label the contents of
this first matter
directly run it, being given
wpf learning notes and mvvmlight
in ViewModelLocator.cs ViewModel folder's being given
the wrong search found a solution:
this line commented out or deleted a reference to the error, add another line reference
wpf learning notes and mvvmlight
which is

using CommonServiceLocator;

This is not being given a

ObservableObject three, mvvmlight framework

Class inherits ObservableObject
course reference to the corresponding packet

using GalaSoft.MvvmLight;

As I understand this is inherited this class, you can change the properties of the response, and the response out of the UI
when the property that is subject to change, update the UI accordingly

Xaml.cs in the form, in the constructor to define the context in which data binding

this.DataContext = ……;

Binding in the xaml file

<TextBlock Text="{Binding Welcom.Introduction}" FontSize="30"></TextBlock>

Open a new thread, which is time-intervals, to update data binding, this will update the content in the window in TextBlock

Guess you like

Origin blog.51cto.com/shuxiayeshou/2464907