Plan
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
Le pluging Silverlight
Eclipse pour MacIntosth
Eclipse pour Windows
Microsoft Visual Studio 2010
Microsoft Blend
1.
Sous Windows, la fin de linstallation, vous pouvez vrifier que tout fonctionne en utilisant le
menu Dmarrer :
2.
Par prcautions, vrifier que vous possder la dernire version. Faire : Help / Check for updates
10
11
3.
12
13
14
4.
15
Puis un MacIntosh :
16
Et sous Windows :
17
18
19
5.
20
21
22
23
24
Et aprs le clic :
25
6.
26
Comme pour lexemple prcdent, laide de la boite outils, on peut monter une interface
minimaliste :
System;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Documents;
System.Windows.Input;
System.Windows.Media;
System.Windows.Media.Animation;
System.Windows.Shapes;
namespace SilverlightApplication2
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void button1_Clic(object sender, RoutedEventArgs e)
{
textBlock1.Text = "demonstration...";
}
}
}
27
28
Ce qui donne :
29
30
31
33
34
35
36
7.
37
38
Slectionner par exemple 3 images comme ci-dessous (attention les photos doivent avoir un nom de
type photoX.jpg o X va de 1 3) :
System;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Documents;
System.Windows.Input;
System.Windows.Media;
System.Windows.Media.Animation;
System.Windows.Shapes;
System.Windows.Media.Imaging;
namespace SilverlightApplication6
{
public partial class MainPage : UserControl
{
int position = 1;
39
public MainPage()
{
InitializeComponent();
Uri URL = new Uri("/img/photo1.jpg", UriKind.Relative);
image1.Source = new BitmapImage(URL);
}
Ce qui donne :
40
System;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Documents;
System.Windows.Input;
System.Windows.Media;
System.Windows.Media.Animation;
System.Windows.Shapes;
System.Windows.Media.Imaging;
namespace SilverlightApplication6
{
public partial class MainPage : UserControl
{
int position = 1;
public MainPage()
{
InitializeComponent();
41
Noter le changement au niveau de ladresse et du type de rfrence qui est maintenant en rfrence
absolue.
Etape 7.5. Tester le code
Attention, maintenant, il faut lancer le test grce au raccourcis F5 Dmarrer le debogage de
Visual Studio.
42
8.
43
44
46
Choisir Objet.
47
48
Allez dans le rpertoire correspondant. Celui-ci doit contenir un rpertoire Glassfish et un autre
nomm docroot.
Sur lexemple ci-dessous, nous avons : ..\6.8\GlassFish_v3\docroot\
49
clientaccesspolicy.xml
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
50
crossdomain.xml
crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domainpolicy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="SOAPAction,Content-Type"/>
</cross-domain-policy>
51
52
System;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Documents;
System.Windows.Input;
System.Windows.Media;
System.Windows.Media.Animation;
System.Windows.Shapes;
namespace SilverlightApplication4
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void button1_Clic(object sender, RoutedEventArgs e)
{
dao.getAllClientsAsync();
}
public void dao_getAllClientsCompleted(object
sender,ServiceReference1.getAllClientsCompletedEventArgs e )
{
53
54
Nous allons :
- mettre en place une base de donnes partir dun script SQL ;
- configurer le serveur SQL server de Microsoft ;
- dfinir la couche LINQ ;
- les services WCF ;
- la page web contenant laccs aux web services.
55
Lancez linstallation.
56
57
58
59
INSERT INTO CRENEAUX ( VERSION, ID_MEDECIN, HDEBUT, MDEBUT, HFIN, MFIN) VALUES ( 1, 2, 12, 40, 12, 0);
INSERT INTO CRENEAUX ( VERSION, ID_MEDECIN, HDEBUT, MDEBUT, HFIN, MFIN) VALUES ( 1, 3, 8, 0, 8, 20);
INSERT INTO CRENEAUX ( VERSION, ID_MEDECIN, HDEBUT, MDEBUT, HFIN, MFIN) VALUES ( 1, 3, 8, 20, 8, 40);
INSERT INTO CRENEAUX ( VERSION, ID_MEDECIN, HDEBUT, MDEBUT, HFIN, MFIN) VALUES ( 1, 3, 8, 40, 9, 0);
INSERT INTO CRENEAUX ( VERSION, ID_MEDECIN, HDEBUT, MDEBUT, HFIN, MFIN) VALUES ( 1, 3, 9, 0, 9, 20);
INSERT INTO CRENEAUX ( VERSION, ID_MEDECIN, HDEBUT, MDEBUT, HFIN, MFIN) VALUES ( 1, 3, 9, 20, 9, 40);
INSERT INTO CRENEAUX ( VERSION, ID_MEDECIN, HDEBUT, MDEBUT, HFIN, MFIN) VALUES ( 1, 3, 9, 40, 10, 0);
INSERT INTO CRENEAUX ( VERSION, ID_MEDECIN, HDEBUT, MDEBUT, HFIN, MFIN) VALUES ( 1, 3, 10, 0, 10, 20);
INSERT INTO CRENEAUX ( VERSION, ID_MEDECIN, HDEBUT, MDEBUT, HFIN, MFIN) VALUES ( 1, 3, 10, 20, 10, 40);
INSERT INTO CRENEAUX ( VERSION, ID_MEDECIN, HDEBUT, MDEBUT, HFIN, MFIN) VALUES ( 1, 3, 10, 40, 12, 0);
INSERT INTO CRENEAUX ( VERSION, ID_MEDECIN, HDEBUT, MDEBUT, HFIN, MFIN) VALUES ( 1, 3, 12, 0, 12, 20);
COMMIT WORK;
INSERT INTO RV ( JOUR, ID_CRENEAU, ID_CLIENT) VALUES ('20060822', 1, 2);
INSERT INTO RV ( JOUR, ID_CRENEAU, ID_CLIENT) VALUES ('20060823', 5, 2);
INSERT INTO RV ( JOUR, ID_CRENEAU, ID_CLIENT) VALUES ('20060823', 20, 4);
INSERT INTO RV ( JOUR, ID_CRENEAU, ID_CLIENT) VALUES ('20060910', 10, 2);
INSERT INTO RV ( JOUR, ID_CRENEAU, ID_CLIENT) VALUES ('20060823', 8, 4);
INSERT INTO RV ( JOUR, ID_CRENEAU, ID_CLIENT) VALUES ('20060823', 7, 3);
COMMIT WORK;
ALTER TABLE RV ADD CONSTRAINT UNQ1_RV UNIQUE (JOUR, ID_CRENEAU);
COMMIT WORK;
60
61
Ajouter une zone daffichage et un bouton. Linterface doit ressembler ce qui suit avec une
Listbox et une Button.
62
Aller dans le menu Affichage pour faire apparaitre lExplorateur de serveurs (sil nest pas
affich).
Faire un clic droit sur Connexion de donnes et choisir Ajouter une connexion.
63
64
Les tables de la base de donnes apparaissent maintenant dans la section Explorateur de serveurs.
65
66
67
68
69
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Runtime.Serialization;
System.ServiceModel;
System.Text;
namespace SilverlightBdD.Web
{
[ServiceContract]
public interface IService1
{
[OperationContract]
void DoWork();
[OperationContract]
List<String> getClients();
}
}
70
System;
System.Collections.Generic;
System.Linq;
System.Runtime.Serialization;
System.ServiceModel;
System.Text;
namespace SilverlightBdD.Web
{
public class Service1 : IService1
{
public void DoWork()
{
}
public List<string> getClients()
{
DataClasses1DataContext dc = new DataClasses1DataContext();
var AllClient = (from Clients in dc.CLIENTS select Clients.NOM);
return AllClient.ToList();
}
}
}
Web Service
SQL Server
Base de donnes
Mdecin
Faire un clic droit sur SilverlightBdD et choisir Ajouter une rfrence de service.
71
Et finalement :
72
Le service web une fois dcouvert, lexplorateur de solution fait apparatre le web service.
73
74
System;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Documents;
System.Windows.Input;
System.Windows.Media;
System.Windows.Media.Animation;
System.Windows.Shapes;
namespace SilverlightApplication2_Alexandre
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void button1_Clic(object sender, RoutedEventArgs e)
{
ServiceReference1.Service1Client dao = new ServiceReference1.Service1Client();
dao.getClientsCompleted += new
EventHandler<ServiceReference1.getClientsCompletedEventArgs>(dao_getAllClientsCompleted);
dao.getClientsAsync();
}
public void dao_getAllClientsCompleted(object sender, ServiceReference1.getClientsCompletedEventArgs
e)
{
foreach (String client in e.Result)
{
listBox1.Items.Add(client);
}
}
}
}
75
10.
76
77
78
79
80
Ajouter un site nomm magasin et faisant rfrence par exemple la racine wwwroot. Ce
rpertoire nest pas vide sur notre machine
81
82
83
Ceci donne un rpertoire sur le disque contenant les fichiers de votre application web.
84
C:\magasindemo\
Vrifier que le fichier se charge correctement en lanant le .html qui se trouve dans le dossier
c:/magasindemo/ : file:///C:/magasindemo/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.html
85
87
Ce qui donnera :
88
89
Il suffit ensuite de faire un clic droit sur Magasin dans ISS et de choisir Ajouter une application.
90
91
92
On obtient :
93
11.
Il sagit dun outil permettant de raliser des interfaces plus facilement quavec Visual Studio 2010.
Cet outil vite en particulier de manipuler manuellement le code xaml.
94
95
Basculez laffichage en mode mixte. Cela vous permet alors de lire le code de la page xaml.
96
Le code xaml permet de modifier facilement les caractristiques de lobjet. Passez la proprit Fill
Red par exemple :
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SilverlightApplication2P.MainPage"
Width="640" Height="480">
<Grid x:Name="LayoutRoot" Background="White">
<Rectangle Fill="Red" Stroke="Black" Height="79" HorizontalAlignment="Left" Margin="74,79,0,0"
VerticalAlignment="Top" Width="134"/>
</Grid>
</UserControl>
97
Lapparence de lobjet peut facilement tre modifie. Par exemple, en allant dans le menu
Transformer, on peut incliner lobjet dans le sens souhait.
98
Il aurait t possible de le faire directement dans le code xml mais cela est moins pratique :
99
Sur le mme principe, dessinez un bouton. Nommez ce bouton Lancer et modifier le texte sur le
bouton avec Play.
100
Vous devriez obtenir une fentre de cration dune ressource. Choisissez le nom dplacement pour
la ressource.
Positionnez la barre verticale jaune sur 1 et dplacer lobjet sur lendroit ou vous dsirer quil
apparaisse la date 1s.
101
102
Vous pouvez vrifier leffet visuel que cela produit, en dplaant la barre jaune avec la souris aux
positions que vous souhaitez.
Pressez F5 pour lancer lexcution et vous obtiendrez une page statique sur laquelle les objets sont
immobiles.
103
104
105
Lancer le code en faisant F5 et vous obtiendrez une page Web dont lanimation dmarre en cliquant
sur le bouton Play.
106
107
108
109
using
using
using
using
using
using
using
using
using
System;
System.Windows;
System.Windows.Controls;
System.Windows.Documents;
System.Windows.Ink;
System.Windows.Input;
System.Windows.Media;
System.Windows.Media.Animation;
System.Windows.Shapes;
namespace SilverlightApplication2P
{
public partial class MainPage : UserControl
{
public MainPage()
{
// Requis pour initialiser des variables
InitializeComponent();
Lancer.Click+=new System.Windows.RoutedEventHandler(Lancer_Click);
buttonStop.Click+=new System.Windows.RoutedEventHandler(buttonStop_Click);
buttonResume.Click+=new System.Windows.RoutedEventHandler(buttonResume_Click);
buttonPause.Click+=new System.Windows.RoutedEventHandler(buttonPause_Click);
}
private void Lancer_Click(object sender, System.Windows.RoutedEventArgs e)
{
// TODO : ajoutez ici limplmentation du gestionnaire dvnements.
deplacement.Begin();
}
private void buttonStop_Click(object sender, System.Windows.RoutedEventArgs e)
{
// TODO : ajoutez ici limplmentation du gestionnaire dvnements.
deplacement.Stop();
}
private void buttonResume_Click(object sender, System.Windows.RoutedEventArgs e)
{
// TODO : ajoutez ici limplmentation du gestionnaire dvnements.
deplacement.Resume();
}
private void buttonPause_Click(object sender, System.Windows.RoutedEventArgs e)
{
// TODO : ajoutez ici limplmentation du gestionnaire dvnements.
deplacement.Pause();
}
}
}
110
111
12.
112
Crez une application avec une image encadre par un Slider comme sur lexemple ci-dessous :
Limage est de type Image avec un champ source renseigne vers logo_UBP.jpg pour notre
exemple :
Le slider va servir controler la rotation de limage. Modifier sa proprit en donnant comme plage
de variation : 0 180 par exemple.
113
Slectionnez limage.
Examiner la partie Transformer (colonne de droite).
Modifier titre dexemple lAngle en le passant de 0 15.
114
115
116
En utilisant le systme de compltion il est facile dattacher une procdure derrire lvnement
ValueChanger dun Slider.
117
118
119
13.
SUPPORTS DE COURS
1. http://www.dotnet-france.com/Cours/Silverlight.html
2. http://www.dotnetfrance.com/Documents/Silverlight/Introduction%20a%20Silverlight.pdf
3. http://www.dotnet-france.com/Documents/Silverlight/Les%20Contr%C3%B4les.pdf
4. http://www.dotnetfrance.com/Documents/Silverlight/Les%20nouveautes%20de%20Silverlight%203%
20Blend%203%20et%20.NET%20RIA%20Services.pdf
5. http://www.dotnet-france.com/Documents/Silverlight/Customisation.pdf
6. http://www.dotnetfrance.com/Documents/Silverlight/Gestion%20d%E2%80%99%C3%A9v%C3%A8
nement%20et%20Commandes.pdf
7. http://www.dotnet-france.com/Documents/Silverlight/Les%20animations.pdf
8. http://broux.developpez.com/articles/csharp/silverlight/
9. http://nico-pyright.developpez.com/tutoriel/vs2008/csharp/silverlightandmysql/
14.
LES LIVRES
120