Caliburn.Micro Jay Tutorial 1 (translation) Caliburn.Micro Jay Tutorial 1 (translation)

Caliburn.Micro Jay Tutorial 1 (translation)

 

Caliburn.Micro Jay Tutorial 1 (original translation)
Caliburn.Micro Jay introductory tutorial 2 Learn Data Binding and Events (translation)
Caliburn.Micro Jay Tutorial 3, events and parameters
Caliburn.Micro Jay Tutorial 4, event aggregator
Caliburn.Micro Jay introductory tutorial 5, the window manager
Caliburn.Micro Jay tutorial 6, Screens and Conductors Profile


 Caliburn.Micro Project Address:

http://caliburnmicro.codeplex.com  (old)

https://github.com/Caliburn-Micro/Caliburn.Micro

【原文地址】Mindscape's Getting Started Tutorial
http://www.mindscapehq.com/blog/index.php/2012/01/12/caliburn-micro-part-1-getting-started/


 Remarks:

Bootstrapper related classes and implementation, the new version has adjusted BootstrapperBase inherit the base class, and calls the InitializeComponent in the constructor (), a new version of the tutorial documentation, please move here to view article I later translation.

Caliburn Micro Part 1: Getting Started


Step 1: Getting Started

Caliburn Micro built on .NET framework 4.0, you need to create an application in Visual Studio 2010 (or higher), first create a new WPF application and add a reference: [Caliburn.Micro.dll and System.Windows .Interactivity.dll], you can find download from Caliburn Micro project.

If you are using Visual Studio, the recommended practice is to use Nuget installation Caliburn.Micro related packages, such as [Caliburn.Micro.Start]

In the new WPF project, delete MainWindow.xaml project file. (That is, the new project comes the main window)
in App.xaml project file, delete StartupUri node properties as follows:

Copy the code
<Application x:Class="CaliburnMicroApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Application.Resources>
 
  </Application.Resources>
</Application>
Copy the code

This step is to rebuild the window initialization, ready to point Caliburn Micro, rather than WPF custom, steps will be pointed to the back of the transfer.

Step 2: The View Model

 Caliburn Micro optimize the View-Model-First mode, the next step is to add a class to represent a view model. Large application may have a plurality of view models, each of which can have different logical views. The following sample code is an empty view of the model. This tutorial is focused on simple start will Caliburn Micro incorporate WPF application, what we do not let the view model now being done (to maintain the most concise).

Copy the code
using Caliburn.Micro;
 
namespace CaliburnMicroApp
{
  public class AppViewModel : PropertyChangedBase
  {
 
  }
}
Copy the code

First thing to note is the name of the class, Caliburn Micro default have a specific naming convention, so you can view models and the associated view match. So, a view model class name should be "ViewModel" end, of course, in front of the name depends on you. Another thing to note is that this class inherits from PropertyChangedBase. This is Caliburn Micro provides for automatic property change notification, so we need to implement INotifyPropertyChanged. Although this sample view model does not do anything, I have inherited PropertyChangedBase and do achieve. Later, when added to the view model attributes will come in handy.

Step 3: The View

To display window, we need to create a view, corresponding to view the model created in the previous step. Only need to add a new user control project, as shown below. Once again, Caliburn Micro default have a specific naming convention, so that you can view correspond to the appropriate view model. View should name "View" and the start end portion to the same name and the corresponding model uses the view. For my example, "AppView" view corresponding "AppViewModel". The following code I also set the width, height, and grid background, so that when you run this application you can see if it works.

Copy the code
<UserControl x:Class="CaliburnMicroApp.AppView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
  <Grid Width="300" Height="300" Background="LightBlue">
 
  </Grid>
</UserControl>
Copy the code

Step 4: The Bootstrapper

Bootstrap mechanism for CaliburnMicro incorporated into your application. It also allows you to require application configuration framework place . For this tutorial, I use a very simple boot program to achieve this:

Copy the code
using Caliburn.Micro;
 
namespace CaliburnMicroApp
{
  public class AppBootstrapper : Bootstrapper<AppViewModel>
  {
  }
}
Copy the code

There are two different CaliburnMicro bootstrappers available. The above settings allow the use of generic type you want to use when starting the view of the model. The final step is to tell the application to use the program guide. By adding your bootloader in xaml resource dictionary to do. After doing so, xaml will now look like this:

Copy the code
<Application x:Class="CaliburnMicroApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:local="clr-namespace:CaliburnMicroApp"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
          <local:AppBootstrapper x:Key="bootstrapper" />
        </ResourceDictionary>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
</Application>
Copy the code

Now, when you run the application, you will see a small window, a light blue background. Your application has now done the most basic support CaliburnMicro.

Caliburn.Micro Jay Tutorial 1 (original translation)
Caliburn.Micro Jay introductory tutorial 2 Learn Data Binding and Events (translation)
Caliburn.Micro Jay Tutorial 3, events and parameters
Caliburn.Micro Jay Tutorial 4, event aggregator
Caliburn.Micro Jay introductory tutorial 5, the window manager
Caliburn.Micro Jay tutorial 6, Screens and Conductors Profile


 Caliburn.Micro Project Address:

http://caliburnmicro.codeplex.com  (old)

https://github.com/Caliburn-Micro/Caliburn.Micro

【原文地址】Mindscape's Getting Started Tutorial
http://www.mindscapehq.com/blog/index.php/2012/01/12/caliburn-micro-part-1-getting-started/


 Remarks:

Bootstrapper related classes and implementation, the new version has adjusted BootstrapperBase inherit the base class, and calls the InitializeComponent in the constructor (), a new version of the tutorial documentation, please move here to view article I later translation.

Caliburn Micro Part 1: Getting Started


Step 1: Getting Started

Caliburn Micro built on .NET framework 4.0, you need to create an application in Visual Studio 2010 (or higher), first create a new WPF application and add a reference: [Caliburn.Micro.dll and System.Windows .Interactivity.dll], you can find download from Caliburn Micro project.

If you are using Visual Studio, the recommended practice is to use Nuget installation Caliburn.Micro related packages, such as [Caliburn.Micro.Start]

In the new WPF project, delete MainWindow.xaml project file. (That is, the new project comes the main window)
in App.xaml project file, delete StartupUri node properties as follows:

Copy the code
<Application x:Class="CaliburnMicroApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Application.Resources>
 
  </Application.Resources>
</Application>
Copy the code

This step is to rebuild the window initialization, ready to point Caliburn Micro, rather than WPF custom, steps will be pointed to the back of the transfer.

Step 2: The View Model

 Caliburn Micro optimize the View-Model-First mode, the next step is to add a class to represent a view model. Large application may have a plurality of view models, each of which can have different logical views. The following sample code is an empty view of the model. This tutorial is focused on simple start will Caliburn Micro incorporate WPF application, what we do not let the view model now being done (to maintain the most concise).

Copy the code
using Caliburn.Micro;
 
namespace CaliburnMicroApp
{
  public class AppViewModel : PropertyChangedBase
  {
 
  }
}
Copy the code

First thing to note is the name of the class, Caliburn Micro default have a specific naming convention, so you can view models and the associated view match. So, a view model class name should be "ViewModel" end, of course, in front of the name depends on you. Another thing to note is that this class inherits from PropertyChangedBase. This is Caliburn Micro provides for automatic property change notification, so we need to implement INotifyPropertyChanged. Although this sample view model does not do anything, I have inherited PropertyChangedBase and do achieve. Later, when added to the view model attributes will come in handy.

Step 3: The View

To display window, we need to create a view, corresponding to view the model created in the previous step. Only need to add a new user control project, as shown below. Once again, Caliburn Micro default have a specific naming convention, so that you can view correspond to the appropriate view model. View should name "View" and the start end portion to the same name and the corresponding model uses the view. For my example, "AppView" view corresponding "AppViewModel". The following code I also set the width, height, and grid background, so that when you run this application you can see if it works.

Copy the code
<UserControl x:Class="CaliburnMicroApp.AppView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
  <Grid Width="300" Height="300" Background="LightBlue">
 
  </Grid>
</UserControl>
Copy the code

Step 4: The Bootstrapper

Bootstrap mechanism for CaliburnMicro incorporated into your application. It also allows you to require application configuration framework place . For this tutorial, I use a very simple boot program to achieve this:

Copy the code
using Caliburn.Micro;
 
namespace CaliburnMicroApp
{
  public class AppBootstrapper : Bootstrapper<AppViewModel>
  {
  }
}
Copy the code

There are two different CaliburnMicro bootstrappers available. The above settings allow the use of generic type you want to use when starting the view of the model. The final step is to tell the application to use the program guide. By adding your bootloader in xaml resource dictionary to do. After doing so, xaml will now look like this:

Copy the code
<Application x:Class="CaliburnMicroApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:local="clr-namespace:CaliburnMicroApp"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
          <local:AppBootstrapper x:Key="bootstrapper" />
        </ResourceDictionary>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
</Application>
Copy the code

Now, when you run the application, you will see a small window, a light blue background. Your application has now done the most basic support CaliburnMicro.

Guess you like

Origin www.cnblogs.com/aijiao/p/11096569.html