Silverlight-Caliburn application framework 1
Silverlight-Caliburn application framework 2
Silverlight-Caliburn application framework 3
Silverlight-Caliburn application framework 4
Silverlight-Caliburn application framework 5
Silverlight-Caliburn application framework 6
The well-known framework in SL may be prism. I believe that even cailburn is your first contact. cailburn and Prism provide the same functions in some aspects, just for example, we have a more intuitive understanding of prism as a UI combination framework, while cailburn is positioned in the UI application framework.
There are not many Chinese tutorials on cailburn, and it is also an accident to come into contact with it. This series only records the process of my recent learning about cailburn, and there is no idea of creating a high-level architecture. In this process, like me, you may encounter concepts you have never touched on. Even so, I don't think it is a problem at least to prevent you from using this framework.
You need to download the installation package from the Caliburn website. You cannot modify the installation path. You can find the relevant files in the c: \ Program Files \ blue spire consulting directory, because I just keep a simple record of the Caliburn process, if you are familiar with Caliburn, it is not suitable for you to read it. We recommend some articles about this in clingingboy.Article.
First, we will familiarize ourselves with this framework through a blog on the official website:
After creating a project, you need to add the relevant DLL (under the Caliburn \ 1.1.0 \ assemblies \ Silverlight 3.0 \ release directory)
Caliburn. Core. dll
Caliburn. presentationframework. dll
Microsoft. Practices. servicelocation. dll
Now we have created two folders, views and viewmodels. Finally, our project architecture is roughly like this.
Note that the cailburn framework provides a default naming method, that is, if you name a view in views as mypageview, then, it will find the corresponding mypageviewmodel file in the viewmodels directory.
Now we need to modify app. CS:
UsingCaliburnwithsilverlight. viewmodels;
UsingCaliburn. presentationframework. ApplicationModel;
PublicPartialClassAPP: caliburnapplication
{
PublicAPP ()
{
Initializecomponent ();
}
Protected Override ObjectCreaterootmodel ()
{
Return NewPageviewmodel ();
}
}
Here we will change the app to inherit from the caliburnapplication class. createrootmodel () returns a pageviewmodel instance, which is similar to setting this. rootvisual and Caliburn will automatically locate the corresponding view for your viewmodel.
We have modified the base class of the app and also need to modify the corresponding XAML:
<PL:CaliburnapplicationXmlns=Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns:X=Http://schemas.microsoft.com/winfx/2006/xaml"
X:Class="Caliburnwithsilverlight. app"
Xmlns:PL="CLR-namespace: Caliburn. presentationframework. ApplicationModel; Assembly = Caliburn. presentationframework"
>
<Application. Resources>
</Application. Resources>
</PL:Caliburnapplication>
At this time, the compilation can be passed. On this basis, we use Caliburn to bind the methods in the VM.
Modify the pageviewmodel and add a method.
Public ClassPageviewmodel: inotifypropertychanged
{
Private String_ Message;
PublicPageviewmodel ()
{
Message ="My first message";
}
Public StringMessage
{
Get{Return_ Message ;}
Set
{
_ Message =Value;
If(Propertychanged! =Null)
{
Propertychanged (This,NewPropertychangedeventargs ("Message"));
}
}
}
Public VoidChangemessage ()
{
Message ="Hello World";
}
Public EventPropertychangedeventhandler propertychanged;
}
We declare a changemessage () to change the message property value. We need to bind this method to the UI,
<Usercontrol Xmlns:PF="CLR-namespace: Caliburn. presentationframework; Assembly = Caliburn. presentationframework"
>
<Grid X:Name="Layoutroot" Background="White">
<Stackpanel Orientation="Vertical">
textblock text = " {binding message} " />
button pf : message . attach = " changemessage " content = " Click me " width = " 98 " margin = " 0 " />
</Stackpanel>
</Grid>
</Usercontrol>
The message. Attach attribute function in the cailburn framework is used to bind a method. At this time, you can run the page and click the button.
The event is triggered. The text of textblock is changed from my first message to Hello world.
This article mainly provides a simple preview of the Caliburn framework, which will be further explored in the content above, and explain some of its concepts according to my understanding. At the same time, if you are familiar with both cailburn and Prism, I hope to correct what I said.