wpf & linq: vb t&t community after hour @ microsoft days 08

23
1 http://community.visual-basic.it/ Alessandro

Upload: alessandrodelsole

Post on 18-May-2015

1.341 views

Category:

Technology


0 download

DESCRIPTION

Demo sull\'uso di LINQ-to-Entities e LINQ-to-XML con Visual Basic 2008 in applicazioni WPF

TRANSCRIPT

Page 1: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

1

http://community.visual-basic.it/Alessandro

Page 2: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

2

http://community.visual-basic.it/Alessandro

Page 3: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

3

http://community.visual-basic.it/Alessandro

Overview di Windows Presentation Foundation

Focus on: Control templates, data-binding

Overview di ADO.NET Entity Framework

Utilizzo di LINQ-to-Entities in WPF

Utilizzo di LINQ-to-Xml in WPF per interfacce dinamiche

Page 4: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

4

http://community.visual-basic.it/Alessandro

Modello unificato che sfrutta DirectX® per la creazione di interfacce grafiche avanzate e moderne (Windows->WPF, Web-> Silverlight) in ottica .NET

Contenuti multimediali (audio,video,animazioni, contenuti 2D/3D) e gestione documenti (XPS, Flow, Open Xml)

Separazione marcata tra lato designer e lato developer

La UI è definita tramite l’eXtensible Application Markup Language (XAML) uguale per grafici e developers

Ciò che faccio con XAML lo posso fare con VB.NET/C#

Page 5: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

5

http://community.visual-basic.it/Alessandro

.NET Framework Client Profile

Rendering hardware dei bmp effects Blur e DropShadow

Splash screen

Shader customizzabili

Direct3D Interop

Page 6: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

6

http://community.visual-basic.it/Alessandro

Visual Studio 2008

Expression Blend 2.0 SP 1

Expression Design 2.0

Blend e Design esportano in XAML riutilizzabile in VS 2008

Page 7: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

7

http://community.visual-basic.it/Alessandro

In WPF i controlli vengono posizionati mediante i panels (contenitori), che ne consentono l’arrangement dinamico.

Questo determina una struttura gerarchica

<Window x:Class=“Window1 ...>

<StackPanel Orientation=“Horizontal”>

<Button Click=“OnClick”/>

<Grid>

<TextBlock Text=“I love WPF”/>

</Grid>

</StackPanel>

</Window>

Page 8: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

8

http://community.visual-basic.it/Alessandro

Definisce la struttura a oggetti dell’interfaccia

Page 9: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

9

http://community.visual-basic.it/Alessandro

Scompone ciascun controllo dell’interfaccia negli elementi che lo compongono

Page 10: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

10

http://community.visual-basic.it/Alessandro

I controlli WPF sono definiti lookless

Posso ridefinire completamente il Visual Tree di un controllo mantenendone il comportamento tipico

Non serve scrivere controlli custom, basta l’overridingSfruttano Styles e Triggers

Non sono consigliabili forme stravaganti!

Lo assegno con una markup extension:

<Button Style=“{DynamicResource MyButtonStyle}”/>

Click Me!Click Me!

Page 11: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

11

http://community.visual-basic.it/Alessandro

Costrutti che ampliano le possibilità di utilizzo di XAML

Tipico esempio di utilizzo nel data-binding

Esempi:

<TextBlock Text=“{Binding Path=MyData}”

<Button Style=“{DynamicResource MyButtonStyle}”/>

Page 12: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

12

http://community.visual-basic.it/Alessandro

Associazione di proprietà di una sorgente dati a controlli dell’interfaccia

Di diversi tipi (one way, two way, one way to source)

Supportati diversi tipi di collezioni (ObservableCollection, List, IEnumerable-IQueryable)

Posso sfruttare le XAML markup extensions

Page 13: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

13

http://community.visual-basic.it/Alessandro

LINQ restituisce IEnumerable e IQueryable, consente conversione in List

Il risultato delle interrogazioni LINQ è fruibile da WPF

Ciò vale anche per LINQ-to-Entities nell’Entity Framework

Posso assegnare le collezioni ottenute alla proprietà ItemsSource di ListBox e ListView

Se uso questi controlli devo definire l’ItemTemplate

Page 14: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

14

http://community.visual-basic.it/Alessandro

Strato evolutivo di ADO.NET

Si lavora su entità logiche e non tabelle (astrazione)

Offre un modello concettuale dei dati (es. tabella Orders su db -> Entità Orders)

Disaccoppiamento tra applicazione e schema del database

Supporto per diversi DMBS (non solo Database SQL)

Supporta relazioni di tipo Many-to-Many

Comodo wizard per generare l’Entity Data Model

Designer di Visual Studio 2008 dedicato

LINQ-to-Entities per interrogare i dati e operazioni CRUD

Page 15: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

15

http://community.visual-basic.it/Alessandro

Sorgente Sorgente datidati

• Infrastruttura per lavorare con

oggetti e operazioni CRUD• Query dinamiche rivolte a

entità e non a tabelle

• Provider .NET per accedere a quanto esposto dall’EDM

• Interrogazione e gestione di

entità in forma managed

• Modello a oggetti per l’accesso

ai dati basato su entità.

Concetto di astrazione. 3 file

Xml (Conceptual model,

Storage Model, Mapping)

Page 16: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

16

http://community.visual-basic.it/Alessandro

• Le entità si gestiscono tramite designer e finestra delle Proprietà

• Le Scalar Properties rappresentano le colonne

• Le Navigation Properties mantengono le relazioni

• Finestre ancorabili Model Browser e Mapping Details

Page 17: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

17

http://community.visual-basic.it/Alessandro

• Si lavora con l’ObjectContext

• Metodo AddTo per Insert

• Metodo DeleteObject per Delete

• Metodo SaveChanges per l’invio dei dati al db

• Query expression per interrogare e filtrare

Page 18: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

18

http://community.visual-basic.it/Alessandro

WPF & LINQWPF & LINQ-to-Entities-to-Entities

Page 19: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

19

http://community.visual-basic.it/Alessandro

LINQ-to-Xml è il provider standard per interrogare e creare documenti Xml

In Visual Basic 2008 possiamo scrivere codice Xml in-line all’interno del codice VB grazie agli XML Literals

I file di codice XAML sono file a struttura Xml

Grazie agli XML Literals di Visual Basic possiamo scrivere file di codice XAML a run-time per creare interfacce dinamiche

Page 20: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

20

http://community.visual-basic.it/Alessandro

Grazie agli XML Literals di Visual Basic possiamo scrivere file di codice XAML a run-time per creare interfacce dinamiche

Page 21: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

21

http://community.visual-basic.it/Alessandro

WPF & LINQ-to-XmlWPF & LINQ-to-Xml

Page 22: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

22

http://community.visual-basic.it/Alessandro

Windows Presentation Foundationhttp://msdn.microsoft.com/it-it/library/cc185038.aspxhttp://community.visual-basic.it/alessandro/category/422.aspx

ADO.NET Entity Frameworkhttp://blogs.msdn.com/adonet/http://msdn.microsoft.com/en-us/library/bb399572.aspx

LINQ-to-Entitieshttp://msdn.microsoft.com/en-us/library/bb386964.aspxhttp://community.visual-basic.it/alessandro/category/500.aspx

LINQ-to-XML e WPFhttp://msdn.microsoft.com/it-it/library/bb387098.aspxhttp://msdn.microsoft.com/it-it/library/bb882629.aspxhttp://community.visual-basic.it/Alessandro/archive/2008/06/05/22972.aspx

Page 23: WPF & LINQ: VB T&T Community After Hour @ Microsoft Days 08

23

http://community.visual-basic.it/Alessandro

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Hyper-V, RemoteApp, Windows logo, Windows Start button, Windows Server Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. All other trademarks are property of their respective owners. The information herein

is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this

presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.