SlideShare une entreprise Scribd logo
1  sur  19
WEBCAST
              ON
HANDS ON TO MAGICAL COMBINATION
 OF WPF AND MVVM ARCHITECTURE

              PRESENTED
                  BY
           SHIBATOSH SINHA

            shibatosh@rediffmail.com
   http://www.facebook.com/Shibatosh.Sinha
A little ‘bit’e of   WPF
What is WPF ?


  The Windows Presentation Foundation (WPF) is a subset of the .NET
  Framework types that are located mostly in the         namespace
  System.Windows and is tailor made for building Windows client
  applications with visually stunning user experiences.

  In other words it means resolution-independent display, usage of
  Extensible Application Markup Language (XAML), powerful data binding,
  control and data templates, various layout options, 2D and 3D graphics,
  animations, styles, flow documents, multimedia and a lot more features
  all rolled into one!
SOME OF THE KEY FEATURES WE MIGHT LIKE TO
SAIL THROUGH FOR TODAY’S SESSION ARE :
RESOLUTION AND DEVICE-INDEPENDENT DISPLAY


 WPF got rid of this huge headache by incorporating Device Independent Pixels
(DPI) which remains 1/96th of an inch, regardless of actual screen resolution.
It is achieved by modifying the screen pixel density. It also uses a coordinate
system of Improved precision for more accurate display.
GRAPHICS AND ANIMATION SUPPORT


 It uses DirectX environment and can take advantage of the graphics hardware
installed in the computer to minimize CPU usage. One highly advantageous
point is that each part of the graphics we draw on screen is vector based and
object oriented, so we have complete control to erase or modify each part of
our display later on
CONTROL TEMPLATES


Wow! Another dream comes true for a developer. Now we can completely
redesign the look of a control as per our wish. For example now each
listboxitem in our listbox can have dynamic images, checkboxes, textboxes,
dropdowns and whatever control we require to display that record. That’s
what you call freedom! It also does one very important thing that is the XAML
which takes care of the appearance and the model class which controls the
behavior now becomes loosely coupled.
1. We define a Control Template
<ControlTemplate TargetType="{x:Type ButtonBase}“ x:Key="btnBasicTemp">
    <Grid Effect="{StaticResource ControlShadowEffect}">
      <Rectangle x:Name="GelBackground“ RadiusX="9“ RadiusY="9"
             Fill="{TemplateBinding Background}“/>
      <ContentPresenter Margin="10,0,10,0“/>
    </Grid>
</ControlTemplate>
2. A Style created for button uses that Control Template
<Style TargetType="{x:Type ButtonBase}“ x:Key="btnBasic">
    <Setter Property="Foreground“ Value="{StaticResource ButtonForegroundDefaultBrush}" />
    <Setter Property="Background" Value="#567890"/>
    <Setter Property="Template“ Value="{StaticResource btnBasicTemp}" />
    <Style.Triggers><MultiTrigger><MultiTrigger.Conditions>
                      <Condition Property="IsMouseOver“ Value="True" />
                      <Condition Property="IsEnabled“ Value="True" />
    </MultiTrigger.Conditions>
                      <Setter Property="Foreground“ Value="{StaticResource btnHoverForeBrush}" />
    </MultiTrigger></Style.Triggers>
</Style>
3. A Button in form uses that Style
          <Button Style="{DynamicResource btnBasic}">Hi!</Button>
EXAMPLE ARCHITECTURE :




              UI Layer

                View Model

                  Business Logic Layer

                     Data Layer

                         Database
EXAMPLE ARCHITECTURE :




     Window              Window1.xaml


INotifyPropertyChanged     GroupsModel.cs – View Model Class


  Data Factory Classes       Groups.cs - Singular & Plural Table classes


        IEnumerable              Data Factory Classes


                                        Database
DEPENDENCY PROPERTY


 It can be used just like a normal property but provides lot more extra features. Its
 value can be calculated indirectly from other usergiven inputs.

• Property value coming from style
<Style x:Key=“DefaultBtnStyle">
<Setter Property="Control.Background" Value=“SteelBlue"/>
</Style>
<Button Style="{StaticResource DefaultBtnStyle}">See my color!</Button>
• Property value coming from data binding
<TextBlock x:Name="txtMembers“ Text="{Binding Members}“/>
• Property value coming from data binding dynamic resource
<Button Style="{DynamicResource AlternativeBtnStyle}">Hi!</Button>
• The property can inherit its value automatically from a parent element in
   the element tree which saves a lot of unnecessary duplication.
• The property can report when the property value changes.
DATA BINDING
It is a process to transfer data between the controls of application UI and the properties of the model class.
There are various modes to choose from depending on the situation. INotifyPropertyChanged is used to
maintain     continuous      synchronization   between       the        binding    target         and binding
source. The UpdateSourceTrigger property of the binding determines which event triggers the update of the
source. ICollectionView is used to implement Sorting, Filtering or Grouping on a data collection.


           UI Layer                                                               View Model
       Binding Target                                                            Binding Source



           Dependency                           One Way                               Property
            Property                            Two Way
                                            One Way To Source
                                                One Time
     Dependency Object                                                         Model Class Object


          ItemSource                                                         Observable Collection
                                          INotifyPropertyChanged
         SelectedItem                                                           Singular Element
DATA TEMPLATE
 It is used to specify how data objects will be displayed in UI.

 <ListBox x:Name="lst"
         ItemsSource="{Binding GroupData}"
         SelectedItem="{Binding CurrentSingularData}">
<ListBox.ItemTemplate>
          <DataTemplate>
                   <StackPanel Orientation="Vertical">
                   <TextBlock x:Name="txtName" Text="{Binding Name}"/>
                   <TextBlock x:Name="txtMembers" Text="{Binding Members}"/>
                   </StackPanel>
                   <DataTemplate.Triggers>
                   <DataTrigger Binding="{Binding Id}“ Value="{x:Null}">
                   <Setter TargetName="txtName“ Property="Text“ Value="Add New..." />
                   </DataTrigger>
                   </DataTemplate.Triggers>
          </DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
MVVM – MODEL-VIEW-VIEWMODEL
This is an architecture with a very loosely coupled design absolutely
tailor-made for the WPF and Silverlight applications.

• What we can see as the UI is known as the View.
• The layer that arranges all the data in presentable format and supplies
them to this View is the ViewModel.
• The ViewModel gets it all from the Model.




View                      ViewModel                           Model
MVVM – MODEL-VIEW-VIEWMODEL (CONTINUED)



The View-ViewModel binding is performed simply by setting a ViewModel
object as the DataContext of a view. If property values in the ViewModel change,
they automatically synchronize the view and ther is no need to write any code to
update the view. As WPF supports Command Binding when we click a button in
the View, a command on the ViewModel executes to perform the requested
action.
The beauty of this architecture lies in the fact that the ViewModel works
independent of the View and so any existing UI design (View) can be altered to
any extent and can be attached to the ViewModel again without any problem.
Same relationship exist between the ViewModel and the Model making it a
really modular and loosely coupled design.
TRIGGERS
A trigger is used to automatically perform some action if a certain condition is
achieved. There are 3 trigger types in WPF.

• Property Triggers
• Event Triggers
• Data Triggers

• Property Triggers are executed when a property reaches a predefined value.
<Style.Triggers>
          <Trigger Property="IsMouseOver“ Value="True">
                   <Setter Property="Background“ Value="#CCFFFF" />
          </Trigger>
</Style.Triggers>
TRIGGERS (CONTINUED)


• Event Triggers are executed when a particular event occurs.

<Button Opacity="0" Content="Watch Me">
 <Button.Triggers>
  <EventTrigger RoutedEvent="FrameworkElement.Loaded">
   <BeginStoryboard Name="ActionName">
    <Storyboard>
     <DoubleAnimation Storyboard.TargetProperty="Opacity"
       Duration="0:0:1" BeginTime="0:0:0.2" To="1.0" />
    </Storyboard>
   </BeginStoryboard>
  </EventTrigger>
 </Button.Triggers>
</Button>
TRIGGERS (CONTINUED)


• Data Triggers are executed when a binding expression reaches a predefined
value.

<DataTemplate.Triggers>
        <DataTrigger Binding="{Binding Id}“ Value="{x:Null}">
        <Setter TargetName="txtName“ Property="Text“ Value="Add New..." />
        </DataTrigger>
</DataTemplate.Triggers>
VALUE CONVERTERS
They are used when our binding source and target properties have incompatible
datatypes and we need somebody to perform that conversion at the time of
binding. These classes are derived from IValueConverter.

1. We have to write some code block like this inside our converter classes
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
     {
       bool check = System.Convert.ToBoolean(value);
       if (check)
           return Visibility.Visible;
       else
           return Visibility.Collapsed;
     }
2. This is how the bolVisConverter is implemented
            <Button Content="Delete“ Visibility="{Binding ElementName=lstStatuses,
            Path=Items.Count, Converter={StaticResource bolVisConverter}}"/>

Contenu connexe

Tendances

MVC on the server and on the client
MVC on the server and on the clientMVC on the server and on the client
MVC on the server and on the clientSebastiano Armeli
 
Introduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developersIntroduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developersAoteaStudios
 
Mvc & java script
Mvc & java scriptMvc & java script
Mvc & java scriptEyal Vardi
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreIMC Institute
 
Imagine Camp Algeria 2014 Build for both session2 mvvm
Imagine Camp Algeria 2014 Build for both session2 mvvmImagine Camp Algeria 2014 Build for both session2 mvvm
Imagine Camp Algeria 2014 Build for both session2 mvvmMicrosoftStudentPartnerAlgeria
 
Web 2 | CSS - Cascading Style Sheets
Web 2 | CSS - Cascading Style SheetsWeb 2 | CSS - Cascading Style Sheets
Web 2 | CSS - Cascading Style SheetsMohammad Imam Hossain
 
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web ToolkitJava Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web ToolkitIMC Institute
 
[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile appsIvano Malavolta
 
KnockOutjs from Scratch
KnockOutjs from ScratchKnockOutjs from Scratch
KnockOutjs from ScratchUdaya Kumar
 
07 association of entities
07 association of entities07 association of entities
07 association of entitiesthirumuru2012
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - AndroidWingston
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web ViewsEmprovise
 
EJB 3.0 course Sildes and matrial
EJB 3.0 course Sildes and matrialEJB 3.0 course Sildes and matrial
EJB 3.0 course Sildes and matrialMohamed Ali Ibrahim
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate TutorialRam132
 
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...jaxconf
 
Overview of WPF in light of Ribbon UI Control
Overview of WPF in light of Ribbon UI ControlOverview of WPF in light of Ribbon UI Control
Overview of WPF in light of Ribbon UI ControlAbhishek Sur
 
In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engineWO Community
 

Tendances (20)

MVC on the server and on the client
MVC on the server and on the clientMVC on the server and on the client
MVC on the server and on the client
 
Introduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developersIntroduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developers
 
Mvc & java script
Mvc & java scriptMvc & java script
Mvc & java script
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : Datastore
 
Imagine Camp Algeria 2014 Build for both session2 mvvm
Imagine Camp Algeria 2014 Build for both session2 mvvmImagine Camp Algeria 2014 Build for both session2 mvvm
Imagine Camp Algeria 2014 Build for both session2 mvvm
 
Web 2 | CSS - Cascading Style Sheets
Web 2 | CSS - Cascading Style SheetsWeb 2 | CSS - Cascading Style Sheets
Web 2 | CSS - Cascading Style Sheets
 
Metaworks3
Metaworks3Metaworks3
Metaworks3
 
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web ToolkitJava Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
 
[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps
 
KnockOutjs from Scratch
KnockOutjs from ScratchKnockOutjs from Scratch
KnockOutjs from Scratch
 
07 association of entities
07 association of entities07 association of entities
07 association of entities
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - Android
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web Views
 
EJB 3.0 course Sildes and matrial
EJB 3.0 course Sildes and matrialEJB 3.0 course Sildes and matrial
EJB 3.0 course Sildes and matrial
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
 
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
 
Overview of WPF in light of Ribbon UI Control
Overview of WPF in light of Ribbon UI ControlOverview of WPF in light of Ribbon UI Control
Overview of WPF in light of Ribbon UI Control
 
Simple Data Binding
Simple Data BindingSimple Data Binding
Simple Data Binding
 
Silverlight Databinding
Silverlight DatabindingSilverlight Databinding
Silverlight Databinding
 
In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engine
 

Similaire à The Magic of WPF & MVVM

Knockoutjs databinding
Knockoutjs databindingKnockoutjs databinding
Knockoutjs databindingBoulos Dib
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinBarry Gervin
 
WPF - Controls &amp; Data
WPF - Controls &amp; DataWPF - Controls &amp; Data
WPF - Controls &amp; DataSharada Gururaj
 
MVVM & Data Binding Library
MVVM & Data Binding Library MVVM & Data Binding Library
MVVM & Data Binding Library 10Clouds
 
Data Binding in Silverlight
Data Binding in SilverlightData Binding in Silverlight
Data Binding in SilverlightBoulos Dib
 
Rp 6 session 2 naresh bhatia
Rp 6  session 2 naresh bhatiaRp 6  session 2 naresh bhatia
Rp 6 session 2 naresh bhatiasapientindia
 
Bringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJSBringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJSBoyan Mihaylov
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!Roberto Messora
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributessonia merchant
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
02.Designing Windows Phone Application
02.Designing Windows Phone Application02.Designing Windows Phone Application
02.Designing Windows Phone ApplicationNguyen Tuan
 
Stephen Kennedy Silverlight 3 Deep Dive
Stephen Kennedy Silverlight 3 Deep DiveStephen Kennedy Silverlight 3 Deep Dive
Stephen Kennedy Silverlight 3 Deep DiveMicrosoftFeed
 
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8netmind
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Mahmoud Hamed Mahmoud
 

Similaire à The Magic of WPF & MVVM (20)

Knockoutjs databinding
Knockoutjs databindingKnockoutjs databinding
Knockoutjs databinding
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
 
WPF - Controls &amp; Data
WPF - Controls &amp; DataWPF - Controls &amp; Data
WPF - Controls &amp; Data
 
MVVM & Data Binding Library
MVVM & Data Binding Library MVVM & Data Binding Library
MVVM & Data Binding Library
 
KnockoutJS and MVVM
KnockoutJS and MVVMKnockoutJS and MVVM
KnockoutJS and MVVM
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
 
Data Binding in Silverlight
Data Binding in SilverlightData Binding in Silverlight
Data Binding in Silverlight
 
Rp 6 session 2 naresh bhatia
Rp 6  session 2 naresh bhatiaRp 6  session 2 naresh bhatia
Rp 6 session 2 naresh bhatia
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Knockoutjs
KnockoutjsKnockoutjs
Knockoutjs
 
Bringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJSBringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJS
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributes
 
Knockoutjs
KnockoutjsKnockoutjs
Knockoutjs
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
02.Designing Windows Phone Application
02.Designing Windows Phone Application02.Designing Windows Phone Application
02.Designing Windows Phone Application
 
Stephen Kennedy Silverlight 3 Deep Dive
Stephen Kennedy Silverlight 3 Deep DiveStephen Kennedy Silverlight 3 Deep Dive
Stephen Kennedy Silverlight 3 Deep Dive
 
Knockout.js
Knockout.jsKnockout.js
Knockout.js
 
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
netmind - Primer Contacto con el Desarrollo de Aplicaciones para Windows 8
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 

Plus de Abhishek Sur

Azure servicefabric
Azure servicefabricAzure servicefabric
Azure servicefabricAbhishek Sur
 
Building a bot with an intent
Building a bot with an intentBuilding a bot with an intent
Building a bot with an intentAbhishek Sur
 
C# 7.0 Hacks and Features
C# 7.0 Hacks and FeaturesC# 7.0 Hacks and Features
C# 7.0 Hacks and FeaturesAbhishek Sur
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to conceptsAbhishek Sur
 
Stream Analytics Service in Azure
Stream Analytics Service in AzureStream Analytics Service in Azure
Stream Analytics Service in AzureAbhishek Sur
 
Designing azure compute and storage infrastructure
Designing azure compute and storage infrastructureDesigning azure compute and storage infrastructure
Designing azure compute and storage infrastructureAbhishek Sur
 
Working with Azure Resource Manager Templates
Working with Azure Resource Manager TemplatesWorking with Azure Resource Manager Templates
Working with Azure Resource Manager TemplatesAbhishek Sur
 
F12 debugging in Ms edge
F12 debugging in Ms edgeF12 debugging in Ms edge
F12 debugging in Ms edgeAbhishek Sur
 
Mobile Services for Windows Azure
Mobile Services for Windows AzureMobile Services for Windows Azure
Mobile Services for Windows AzureAbhishek Sur
 
Service bus to build Bridges
Service bus to build BridgesService bus to build Bridges
Service bus to build BridgesAbhishek Sur
 
Windows azure pack overview
Windows azure pack overviewWindows azure pack overview
Windows azure pack overviewAbhishek Sur
 
AMicrosoft azure hyper v recovery manager overview
AMicrosoft azure hyper v recovery manager overviewAMicrosoft azure hyper v recovery manager overview
AMicrosoft azure hyper v recovery manager overviewAbhishek Sur
 
Di api di server b1 ws
Di api di server b1 wsDi api di server b1 ws
Di api di server b1 wsAbhishek Sur
 
Integrating cortana with wp8 app
Integrating cortana with wp8 appIntegrating cortana with wp8 app
Integrating cortana with wp8 appAbhishek Sur
 
Asp.net performance
Asp.net performanceAsp.net performance
Asp.net performanceAbhishek Sur
 
SQL Server2012 Enhancements
SQL Server2012 EnhancementsSQL Server2012 Enhancements
SQL Server2012 EnhancementsAbhishek Sur
 
Dev days Visual Studio 2012 Enhancements
Dev days Visual Studio 2012 EnhancementsDev days Visual Studio 2012 Enhancements
Dev days Visual Studio 2012 EnhancementsAbhishek Sur
 
Hidden Facts of .NET Language Gems
Hidden Facts of .NET Language GemsHidden Facts of .NET Language Gems
Hidden Facts of .NET Language GemsAbhishek Sur
 
ASP.NET 4.5 webforms
ASP.NET 4.5 webformsASP.NET 4.5 webforms
ASP.NET 4.5 webformsAbhishek Sur
 

Plus de Abhishek Sur (20)

Azure servicefabric
Azure servicefabricAzure servicefabric
Azure servicefabric
 
Building a bot with an intent
Building a bot with an intentBuilding a bot with an intent
Building a bot with an intent
 
Code review
Code reviewCode review
Code review
 
C# 7.0 Hacks and Features
C# 7.0 Hacks and FeaturesC# 7.0 Hacks and Features
C# 7.0 Hacks and Features
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
Stream Analytics Service in Azure
Stream Analytics Service in AzureStream Analytics Service in Azure
Stream Analytics Service in Azure
 
Designing azure compute and storage infrastructure
Designing azure compute and storage infrastructureDesigning azure compute and storage infrastructure
Designing azure compute and storage infrastructure
 
Working with Azure Resource Manager Templates
Working with Azure Resource Manager TemplatesWorking with Azure Resource Manager Templates
Working with Azure Resource Manager Templates
 
F12 debugging in Ms edge
F12 debugging in Ms edgeF12 debugging in Ms edge
F12 debugging in Ms edge
 
Mobile Services for Windows Azure
Mobile Services for Windows AzureMobile Services for Windows Azure
Mobile Services for Windows Azure
 
Service bus to build Bridges
Service bus to build BridgesService bus to build Bridges
Service bus to build Bridges
 
Windows azure pack overview
Windows azure pack overviewWindows azure pack overview
Windows azure pack overview
 
AMicrosoft azure hyper v recovery manager overview
AMicrosoft azure hyper v recovery manager overviewAMicrosoft azure hyper v recovery manager overview
AMicrosoft azure hyper v recovery manager overview
 
Di api di server b1 ws
Di api di server b1 wsDi api di server b1 ws
Di api di server b1 ws
 
Integrating cortana with wp8 app
Integrating cortana with wp8 appIntegrating cortana with wp8 app
Integrating cortana with wp8 app
 
Asp.net performance
Asp.net performanceAsp.net performance
Asp.net performance
 
SQL Server2012 Enhancements
SQL Server2012 EnhancementsSQL Server2012 Enhancements
SQL Server2012 Enhancements
 
Dev days Visual Studio 2012 Enhancements
Dev days Visual Studio 2012 EnhancementsDev days Visual Studio 2012 Enhancements
Dev days Visual Studio 2012 Enhancements
 
Hidden Facts of .NET Language Gems
Hidden Facts of .NET Language GemsHidden Facts of .NET Language Gems
Hidden Facts of .NET Language Gems
 
ASP.NET 4.5 webforms
ASP.NET 4.5 webformsASP.NET 4.5 webforms
ASP.NET 4.5 webforms
 

Dernier

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Dernier (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

The Magic of WPF & MVVM

  • 1. WEBCAST ON HANDS ON TO MAGICAL COMBINATION OF WPF AND MVVM ARCHITECTURE PRESENTED BY SHIBATOSH SINHA shibatosh@rediffmail.com http://www.facebook.com/Shibatosh.Sinha
  • 3. What is WPF ? The Windows Presentation Foundation (WPF) is a subset of the .NET Framework types that are located mostly in the namespace System.Windows and is tailor made for building Windows client applications with visually stunning user experiences. In other words it means resolution-independent display, usage of Extensible Application Markup Language (XAML), powerful data binding, control and data templates, various layout options, 2D and 3D graphics, animations, styles, flow documents, multimedia and a lot more features all rolled into one!
  • 4. SOME OF THE KEY FEATURES WE MIGHT LIKE TO SAIL THROUGH FOR TODAY’S SESSION ARE :
  • 5. RESOLUTION AND DEVICE-INDEPENDENT DISPLAY WPF got rid of this huge headache by incorporating Device Independent Pixels (DPI) which remains 1/96th of an inch, regardless of actual screen resolution. It is achieved by modifying the screen pixel density. It also uses a coordinate system of Improved precision for more accurate display.
  • 6. GRAPHICS AND ANIMATION SUPPORT It uses DirectX environment and can take advantage of the graphics hardware installed in the computer to minimize CPU usage. One highly advantageous point is that each part of the graphics we draw on screen is vector based and object oriented, so we have complete control to erase or modify each part of our display later on
  • 7. CONTROL TEMPLATES Wow! Another dream comes true for a developer. Now we can completely redesign the look of a control as per our wish. For example now each listboxitem in our listbox can have dynamic images, checkboxes, textboxes, dropdowns and whatever control we require to display that record. That’s what you call freedom! It also does one very important thing that is the XAML which takes care of the appearance and the model class which controls the behavior now becomes loosely coupled.
  • 8. 1. We define a Control Template <ControlTemplate TargetType="{x:Type ButtonBase}“ x:Key="btnBasicTemp"> <Grid Effect="{StaticResource ControlShadowEffect}"> <Rectangle x:Name="GelBackground“ RadiusX="9“ RadiusY="9" Fill="{TemplateBinding Background}“/> <ContentPresenter Margin="10,0,10,0“/> </Grid> </ControlTemplate> 2. A Style created for button uses that Control Template <Style TargetType="{x:Type ButtonBase}“ x:Key="btnBasic"> <Setter Property="Foreground“ Value="{StaticResource ButtonForegroundDefaultBrush}" /> <Setter Property="Background" Value="#567890"/> <Setter Property="Template“ Value="{StaticResource btnBasicTemp}" /> <Style.Triggers><MultiTrigger><MultiTrigger.Conditions> <Condition Property="IsMouseOver“ Value="True" /> <Condition Property="IsEnabled“ Value="True" /> </MultiTrigger.Conditions> <Setter Property="Foreground“ Value="{StaticResource btnHoverForeBrush}" /> </MultiTrigger></Style.Triggers> </Style> 3. A Button in form uses that Style <Button Style="{DynamicResource btnBasic}">Hi!</Button>
  • 9. EXAMPLE ARCHITECTURE : UI Layer View Model Business Logic Layer Data Layer Database
  • 10. EXAMPLE ARCHITECTURE : Window Window1.xaml INotifyPropertyChanged GroupsModel.cs – View Model Class Data Factory Classes Groups.cs - Singular & Plural Table classes IEnumerable Data Factory Classes Database
  • 11. DEPENDENCY PROPERTY It can be used just like a normal property but provides lot more extra features. Its value can be calculated indirectly from other usergiven inputs. • Property value coming from style <Style x:Key=“DefaultBtnStyle"> <Setter Property="Control.Background" Value=“SteelBlue"/> </Style> <Button Style="{StaticResource DefaultBtnStyle}">See my color!</Button> • Property value coming from data binding <TextBlock x:Name="txtMembers“ Text="{Binding Members}“/> • Property value coming from data binding dynamic resource <Button Style="{DynamicResource AlternativeBtnStyle}">Hi!</Button> • The property can inherit its value automatically from a parent element in the element tree which saves a lot of unnecessary duplication. • The property can report when the property value changes.
  • 12. DATA BINDING It is a process to transfer data between the controls of application UI and the properties of the model class. There are various modes to choose from depending on the situation. INotifyPropertyChanged is used to maintain continuous synchronization between the binding target and binding source. The UpdateSourceTrigger property of the binding determines which event triggers the update of the source. ICollectionView is used to implement Sorting, Filtering or Grouping on a data collection. UI Layer View Model Binding Target Binding Source Dependency One Way Property Property Two Way One Way To Source One Time Dependency Object Model Class Object ItemSource Observable Collection INotifyPropertyChanged SelectedItem Singular Element
  • 13. DATA TEMPLATE It is used to specify how data objects will be displayed in UI. <ListBox x:Name="lst" ItemsSource="{Binding GroupData}" SelectedItem="{Binding CurrentSingularData}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Vertical"> <TextBlock x:Name="txtName" Text="{Binding Name}"/> <TextBlock x:Name="txtMembers" Text="{Binding Members}"/> </StackPanel> <DataTemplate.Triggers> <DataTrigger Binding="{Binding Id}“ Value="{x:Null}"> <Setter TargetName="txtName“ Property="Text“ Value="Add New..." /> </DataTrigger> </DataTemplate.Triggers> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
  • 14. MVVM – MODEL-VIEW-VIEWMODEL This is an architecture with a very loosely coupled design absolutely tailor-made for the WPF and Silverlight applications. • What we can see as the UI is known as the View. • The layer that arranges all the data in presentable format and supplies them to this View is the ViewModel. • The ViewModel gets it all from the Model. View ViewModel Model
  • 15. MVVM – MODEL-VIEW-VIEWMODEL (CONTINUED) The View-ViewModel binding is performed simply by setting a ViewModel object as the DataContext of a view. If property values in the ViewModel change, they automatically synchronize the view and ther is no need to write any code to update the view. As WPF supports Command Binding when we click a button in the View, a command on the ViewModel executes to perform the requested action. The beauty of this architecture lies in the fact that the ViewModel works independent of the View and so any existing UI design (View) can be altered to any extent and can be attached to the ViewModel again without any problem. Same relationship exist between the ViewModel and the Model making it a really modular and loosely coupled design.
  • 16. TRIGGERS A trigger is used to automatically perform some action if a certain condition is achieved. There are 3 trigger types in WPF. • Property Triggers • Event Triggers • Data Triggers • Property Triggers are executed when a property reaches a predefined value. <Style.Triggers> <Trigger Property="IsMouseOver“ Value="True"> <Setter Property="Background“ Value="#CCFFFF" /> </Trigger> </Style.Triggers>
  • 17. TRIGGERS (CONTINUED) • Event Triggers are executed when a particular event occurs. <Button Opacity="0" Content="Watch Me"> <Button.Triggers> <EventTrigger RoutedEvent="FrameworkElement.Loaded"> <BeginStoryboard Name="ActionName"> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:1" BeginTime="0:0:0.2" To="1.0" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button>
  • 18. TRIGGERS (CONTINUED) • Data Triggers are executed when a binding expression reaches a predefined value. <DataTemplate.Triggers> <DataTrigger Binding="{Binding Id}“ Value="{x:Null}"> <Setter TargetName="txtName“ Property="Text“ Value="Add New..." /> </DataTrigger> </DataTemplate.Triggers>
  • 19. VALUE CONVERTERS They are used when our binding source and target properties have incompatible datatypes and we need somebody to perform that conversion at the time of binding. These classes are derived from IValueConverter. 1. We have to write some code block like this inside our converter classes public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { bool check = System.Convert.ToBoolean(value); if (check) return Visibility.Visible; else return Visibility.Collapsed; } 2. This is how the bolVisConverter is implemented <Button Content="Delete“ Visibility="{Binding ElementName=lstStatuses, Path=Items.Count, Converter={StaticResource bolVisConverter}}"/>