SlideShare ist ein Scribd-Unternehmen logo
1 von 196
WPF: Binding




     Learn More @ http://www.learnnowonline.com
        Copyright © by Application Developers Training Company
Objectives




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Objectives
• Learn to use Binding objects to bind
  data sources and targets




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Objectives
• Learn to use Binding objects to bind
  data sources and targets
• Add data converters to manage
  conversion during the binding process




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Objectives
• Learn to use Binding objects to bind
  data sources and targets
• Add data converters to manage
  conversion during the binding process
• Use data templates to modify the
  layout of bound data in lists



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda




     Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Agenda
• Introducing Binding




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• Introducing Binding
• Working with Type Converters




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• Introducing Binding
• Working with Type Converters
• Binding Lists and Data Templates




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
•   Introducing Binding
•   Working with Type Converters
•   Binding Lists and Data Templates
•   Using Binding and Data Templates




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Introducing Binding




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Introducing Binding
• Often need to update one element with
  information from another




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Introducing Binding
• Often need to update one element with
  information from another
• Display information from collection of
  objects in list, or combo box




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Introducing Binding
• Often need to update one element with
  information from another
• Display information from collection of
  objects in list, or combo box
• Or need to work with data from database




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Introducing Binding
• Often need to update one element with
  information from another
• Display information from collection of
  objects in list, or combo box
• Or need to work with data from database
• In all these cases




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Introducing Binding
• Often need to update one element with
  information from another
• Display information from collection of
  objects in list, or combo box
• Or need to work with data from database
• In all these cases
  • Simplest solution is to bind data from binding
   source to target




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Introducing Binding
• Often need to update one element with
  information from another
• Display information from collection of
  objects in list, or combo box
• Or need to work with data from database
• In all these cases
  • Simplest solution is to bind data from binding
   source to target
• In other words—need some way to
  perform binding

           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
When to Use Binding?




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
When to Use Binding?
• Display in the number of characters in a
  text box, in a TextBlock control




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
When to Use Binding?
• Display in the number of characters in a
  text box, in a TextBlock control
• Display the value of Slider control in a
  TextBlock




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
When to Use Binding?
• Display in the number of characters in a
  text box, in a TextBlock control
• Display the value of Slider control in a
  TextBlock
• Display list of customers in ListBox




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
When to Use Binding?
• Display in the number of characters in a
  text box, in a TextBlock control
• Display the value of Slider control in a
  TextBlock
• Display list of customers in ListBox
• Display customer’s photo in Image control




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
When to Use Binding?
• Display in the number of characters in a
  text box, in a TextBlock control
• Display the value of Slider control in a
  TextBlock
• Display list of customers in ListBox
• Display customer’s photo in Image control
• Display and edit customer’s name in
  TextBox

          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Connecting Sources and
Targets




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Connecting Sources and
Targets
• Every time you use binding




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Connecting Sources and
Targets
• Every time you use binding
  • Must supply source for data, and target




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Connecting Sources and
Targets
• Every time you use binding
  • Must supply source for data, and target
  • Normally, target is dependency property
   of some user interface element




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Connecting Sources and
Targets
• Every time you use binding
  • Must supply source for data, and target
  • Normally, target is dependency property
   of some user interface element




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Connecting Sources and
Targets




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Connecting Sources and
Targets
• Binding source can be any property of
  any CLR object




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Connecting Sources and
Targets
• Binding source can be any property of
  any CLR object
• Binding object connects source to
  binding target




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Connecting Sources and
Targets
• Binding source can be any property of
  any CLR object
• Binding object connects source to
  binding target
  • Must be dependency property of some
   FrameworkElement object




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Under the Hood




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Under the Hood
• When using binding in XAML




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Under the Hood
• When using binding in XAML
  • Create instance of Binding class, setting
   various properties that affect its behavior




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Under the Hood
• When using binding in XAML
  • Create instance of Binding class, setting
   various properties that affect its behavior
• XAML provides binding markup extension




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Under the Hood
• When using binding in XAML
  • Create instance of Binding class, setting
   various properties that affect its behavior
• XAML provides binding markup extension
  • Hides this fact, but still working with Binding
   object




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Under the Hood
• When using binding in XAML
  • Create instance of Binding class, setting
   various properties that affect its behavior
• XAML provides binding markup extension
  • Hides this fact, but still working with Binding
    object
  • Completely transparent if you create Binding
    object in code




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Under the Hood
• When using binding in XAML
  • Create instance of Binding class, setting
    various properties that affect its behavior
• XAML provides binding markup extension
  • Hides this fact, but still working with Binding
    object
  • Completely transparent if you create Binding
    object in code
• Can set Mode property of Binding to
  control direction of data flow (one/two

           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Value Converters




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Value Converters
• Value Converter block in figure represents
  instance of class that implements
  System.Windows.Data.IValueConverter
  interface




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Value Converters
• Value Converter block in figure represents
  instance of class that implements
  System.Windows.Data.IValueConverter
  interface
• Doing binding declaratively, in XAML, often
  requires value converter




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Value Converters
• Value Converter block in figure represents
  instance of class that implements
  System.Windows.Data.IValueConverter
  interface
• Doing binding declaratively, in XAML, often
  requires value converter
  • Select a customer from a ListBox, display
    combined FirstName and LastName fields in
    TextBlock




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Value Converters
• Value Converter block in figure represents
  instance of class that implements
  System.Windows.Data.IValueConverter
  interface
• Doing binding declaratively, in XAML, often
  requires value converter
  • Select a customer from a ListBox, display
    combined FirstName and LastName fields in
    TextBlock
  • Select an integer, bind to BorderThickness of
    Border



            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Value Converters
• Value Converter block in figure represents
  instance of class that implements
  System.Windows.Data.IValueConverter
  interface
• Doing binding declaratively, in XAML, often
  requires value converter
  • Select a customer from a ListBox, display
    combined FirstName and LastName fields in
    TextBlock
  • Select an integer, bind to BorderThickness of
    Border
     • Can’t bind directly—BorderThickness is a Thickness


            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
A Few Simple Examples




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
A Few Simple Examples
• DEMO




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Binding Details




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Binding Details
• Standard Binding markup extension
  includes ElementName and Path
  attributes:




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Binding Details
• Standard Binding markup extension
  includes ElementName and Path
  attributes:
  • Text=
    "{Binding ElementName=DemoSlider,
      Path=Value}"




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Binding Details
• Standard Binding markup extension
  includes ElementName and Path
  attributes:
  • Text=
    "{Binding ElementName=DemoSlider,
      Path=Value}"
• Path attribute not required:



            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Binding Details
• Standard Binding markup extension
  includes ElementName and Path
  attributes:
  • Text=
    "{Binding ElementName=DemoSlider,
      Path=Value}"
• Path attribute not required:
  • Text="{Binding Value,
            ElementName=DemoSlider }"

            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Binding Details




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Binding Details
• Path property can refer to property, or
  property of a property, or indexed
  property




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Binding Details
• Path property can refer to property, or
  property of a property, or indexed
  property
• Need to refer to an attached property?




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Binding Details
• Path property can refer to property, or
  property of a property, or indexed
  property
• Need to refer to an attached property?
  • Grid.Row, for example




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Binding Details
• Path property can refer to property, or
  property of a property, or indexed
  property
• Need to refer to an attached property?
  • Grid.Row, for example
  • Set Path property to (Grid.Row) (in
   parentheses)



          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Binding Details




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Binding Details
• Binding Markup extension shortcut for
  child element syntax:




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Binding Details
• Binding Markup extension shortcut for
  child element syntax:
   <TextBox Width="40"
            Name="DemoTextBox"
            Height="23">
     <TextBox.Text>
       <Binding ElementName="DemoSlider"
                Path="Value" />
     </TextBox.Text>
   </TextBox>


         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Setting the Binding Mode




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Setting the Binding Mode
• In previous demo, data moves from Slider
  to TextBox




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Setting the Binding Mode
• In previous demo, data moves from Slider
  to TextBox
  • Changes you make in TextBox have no effect
   on slider




          Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Setting the Binding Mode
• In previous demo, data moves from Slider
  to TextBox
  • Changes you make in TextBox have no effect
   on slider
• Binding is one-way: Data moves in one
  direction




          Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Setting the Binding Mode
• In previous demo, data moves from Slider
  to TextBox
  • Changes you make in TextBox have no effect
   on slider
• Binding is one-way: Data moves in one
  direction
• Set Mode property of Binding to change




          Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Setting the Binding Mode
• In previous demo, data moves from Slider
  to TextBox
  • Changes you make in TextBox have no effect
   on slider
• Binding is one-way: Data moves in one
  direction
• Set Mode property of Binding to change
• Set Mode to:


          Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Setting the Binding Mode
• In previous demo, data moves from Slider
  to TextBox
  • Changes you make in TextBox have no effect
   on slider
• Binding is one-way: Data moves in one
  direction
• Set Mode property of Binding to change
• Set Mode to:
  • OneTime


          Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Additional Binding Mode Options
(WPF)




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Additional Binding Mode Options
(WPF)
• Can also set Mode to:




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Additional Binding Mode Options
(WPF)
• Can also set Mode to:
  • OneWayToSource




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Additional Binding Mode Options
(WPF)
• Can also set Mode to:
  • OneWayToSource
  • Default




          Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
DEMO




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
DEMO
• Two-way binding, SimpleBinding3




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
A Simple Example




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
A Simple Example
• Enter text into TextBox, update
  TextBlock with length of the text




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
A Simple Example
• Enter text into TextBox, update
  TextBlock with length of the text
• Could react to TextChanged event of
  TextBox




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
A Simple Example
• Enter text into TextBox, update
  TextBlock with length of the text
• Could react to TextChanged event of
  TextBox
• Better: Bind Text property of TextBlock
  to Text.Length property of TextBox



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
A Simple Example
• Enter text into TextBox, update
  TextBlock with length of the text
• Could react to TextChanged event of
  TextBox
• Better: Bind Text property of TextBlock
  to Text.Length property of TextBox
  • Points out that binding can use
   expressions

          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
DEMO




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
DEMO
• SimpleBinding4




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda




     Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Agenda
• Introducing Binding




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• Introducing Binding
• Working with Type Converters




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Agenda
• Introducing Binding
• Working with Type Converters
• Binding Lists and Data Templates




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
•   Introducing Binding
•   Working with Type Converters
•   Binding Lists and Data Templates
•   Using Binding and Data Templates




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Working with Type
Converters




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Working with Type
Converters
• Every example so far moved data from
  source to target without modifying
  data




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Working with Type
Converters
• Every example so far moved data from
  source to target without modifying
  data
  • Or relied on built-in type converters




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Working with Type
Converters
• Every example so far moved data from
  source to target without modifying
  data
  • Or relied on built-in type converters
• What happens when source to target
  requires conversion?



          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Working with Type
Converters
• Every example so far moved data from
  source to target without modifying
  data
  • Or relied on built-in type converters
• What happens when source to target
  requires conversion?
• You have color name, want to apply to
  a property that requires a brush?

          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Working with Type
Converters
• Every example so far moved data from
  source to target without modifying
  data
  • Or relied on built-in type converters
• What happens when source to target
  requires conversion?
• You have color name, want to apply to
  a property that requires a brush?
  • How can you convert during the binding
   process? More @ http://www.learnnowonline.com
         Learn
               Copyright © by Application Developers Training Company
Type Converters to the
Rescue




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Type Converters to the
Rescue
• Type converter injects itself into the
  binding process




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Type Converters to the
Rescue
• Type converter injects itself into the
  binding process
  • Converts data from the source to the target
    type




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Type Converters to the
Rescue
• Type converter injects itself into the
  binding process
  • Converts data from the source to the target
    type
• Must implement
  System.Windows.Data.IValueConverter
  interface




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Type Converters to the
Rescue
• Type converter injects itself into the
  binding process
  • Converts data from the source to the target
    type
• Must implement
  System.Windows.Data.IValueConverter
  interface
  • Two methods: Convert and ConvertBack




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Type Converters to the
Rescue
• Type converter injects itself into the
  binding process
  • Converts data from the source to the target
    type
• Must implement
  System.Windows.Data.IValueConverter
  interface
  • Two methods: Convert and ConvertBack
• Simple to create converter, in general

           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Using the StringFormat
Property




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Using the StringFormat
Property
• Many conversions consist of formatting
  a string




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Using the StringFormat
Property
• Many conversions consist of formatting
  a string
• Could create a type converter; not
  necessary




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Using the StringFormat
Property
• Many conversions consist of formatting
  a string
• Could create a type converter; not
  necessary
• Convert a value into a formatted
  string?



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Using the StringFormat
Property
• Many conversions consist of formatting
  a string
• Could create a type converter; not
  necessary
• Convert a value into a formatted
  string?
  • Can often use StringFormat property



          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
DEMO




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
DEMO
• BindingWithConverter1




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
StringFormat Details




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
StringFormat Details
• Simplest format: StringFormat=0.0




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
StringFormat Details
• Simplest format: StringFormat=0.0
• Can also specify numeric formatting
  string, as if calling String.Format method:




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
StringFormat Details
• Simplest format: StringFormat=0.0
• Can also specify numeric formatting
  string, as if calling String.Format method:
  • StringFormat={}{0:F1}




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
StringFormat Details
• Simplest format: StringFormat=0.0
• Can also specify numeric formatting
  string, as if calling String.Format method:
  • StringFormat={}{0:F1}
  • {} “escapes” formatting string




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
StringFormat Details
• Simplest format: StringFormat=0.0
• Can also specify numeric formatting
  string, as if calling String.Format method:
  • StringFormat={}{0:F1}
  • {} “escapes” formatting string
  • Include text, don’t need escape




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
StringFormat Details
• Simplest format: StringFormat=0.0
• Can also specify numeric formatting
  string, as if calling String.Format method:
  • StringFormat={}{0:F1}
  • {} “escapes” formatting string
  • Include text, don’t need escape
      • StringFormat=The value is: {0:F1}




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
StringFormat Details
• Simplest format: StringFormat=0.0
• Can also specify numeric formatting
  string, as if calling String.Format method:
  • StringFormat={}{0:F1}
  • {} “escapes” formatting string
  • Include text, don’t need escape
      • StringFormat=The value is: {0:F1}
• More tricks:



            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
StringFormat Details
• Simplest format: StringFormat=0.0
• Can also specify numeric formatting
  string, as if calling String.Format method:
  • StringFormat={}{0:F1}
  • {} “escapes” formatting string
  • Include text, don’t need escape
      • StringFormat=The value is: {0:F1}
• More tricks:
  • Can bind to multiple elements using
    MultiBinding


            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
StringFormat Details
• Simplest format: StringFormat=0.0
• Can also specify numeric formatting
  string, as if calling String.Format method:
  • StringFormat={}{0:F1}
  • {} “escapes” formatting string
  • Include text, don’t need escape
      • StringFormat=The value is: {0:F1}
• More tricks:
  • Can bind to multiple elements using
    MultiBinding
     • Check it out!

            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Using a Type Converter




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Using a Type Converter
• Sometimes, StringFormat can’t do the job




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Using a Type Converter
• Sometimes, StringFormat can’t do the job
  • Will need to run code as data transfers




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Using a Type Converter
• Sometimes, StringFormat can’t do the job
  • Will need to run code as data transfers
  • Need a type converter




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Using a Type Converter
• Sometimes, StringFormat can’t do the job
  • Will need to run code as data transfers
  • Need a type converter
• Determine source and target data types




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Using a Type Converter
• Sometimes, StringFormat can’t do the job
  • Will need to run code as data transfers
  • Need a type converter
• Determine source and target data types
  • Write code to perform the conversion




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Using a Type Converter
• Sometimes, StringFormat can’t do the job
  • Will need to run code as data transfers
  • Need a type converter
• Determine source and target data types
  • Write code to perform the conversion
  • Perhaps write code to convert back (for two-way
    binding)




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Using a Type Converter
• Sometimes, StringFormat can’t do the job
  • Will need to run code as data transfers
  • Need a type converter
• Determine source and target data types
  • Write code to perform the conversion
  • Perhaps write code to convert back (for two-way
    binding)
• Sample binds integer from combo box to
  BorderThickness property


            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Using a Type Converter
• Sometimes, StringFormat can’t do the job
  • Will need to run code as data transfers
  • Need a type converter
• Determine source and target data types
  • Write code to perform the conversion
  • Perhaps write code to convert back (for two-way
    binding)
• Sample binds integer from combo box to
  BorderThickness property
  • What’s the problem? Thickness structure has four


            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Creating the Type Converter




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Creating the Type Converter
• Attempt to bind SelectedValue of
  ComboBox to BorderThickness of
  Border, and fails




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Creating the Type Converter
• Attempt to bind SelectedValue of
  ComboBox to BorderThickness of
  Border, and fails
• Need type (or value) converter




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Converters




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Converters
• Implement IValueConverter interface




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Converters
• Implement IValueConverter interface
• Requires Convert and ConvertBack
  methods




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Converters
• Implement IValueConverter interface
• Requires Convert and ConvertBack
  methods
• Parameters:




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Converters
• Implement IValueConverter interface
• Requires Convert and ConvertBack
  methods
• Parameters:
  • value (System.Object)




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Converters
• Implement IValueConverter interface
• Requires Convert and ConvertBack
  methods
• Parameters:
  • value (System.Object)
  • targetType (System.Type)




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Converters
• Implement IValueConverter interface
• Requires Convert and ConvertBack
  methods
• Parameters:
  • value (System.Object)
  • targetType (System.Type)
  • parameter (System.Object)



          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Converters
• Implement IValueConverter interface
• Requires Convert and ConvertBack
  methods
• Parameters:
  • value (System.Object)
  • targetType (System.Type)
  • parameter (System.Object)
  • culture (System.Globalization.Culture)

          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Converter Warning




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Converter Warning
• Converter doesn’t trap exceptions




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Converter Warning
• Converter doesn’t trap exceptions
  • Treated as runtime errors




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Converter Warning
• Converter doesn’t trap exceptions
  • Treated as runtime errors
• You must trap and handle all runtime
  errors




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Converter Warning
• Converter doesn’t trap exceptions
  • Treated as runtime errors
• You must trap and handle all runtime
  errors
  • Return DependencyProperty.UnsetValue
   on error




          Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Converter Warning
• Converter doesn’t trap exceptions
  • Treated as runtime errors
• You must trap and handle all runtime
  errors
  • Return DependencyProperty.UnsetValue
   on error
• Not handled in this simple demo


          Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Converter Warning
• Converter doesn’t trap exceptions
  • Treated as runtime errors
• You must trap and handle all runtime
  errors
  • Return DependencyProperty.UnsetValue
   on error
• Not handled in this simple demo
  • Worth considering!

          Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
DEMO




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
DEMO
• IntegerToThicknessConverter




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Referencing the Type
Converter




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Referencing the Type
Converter
• Need way to refer to type converter in
  XAML




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Referencing the Type
Converter
• Need way to refer to type converter in
  XAML
• Like any other resource, declare instance
  in resources; UserControl.Resources in
  demo




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Referencing the Type
Converter
• Need way to refer to type converter in
  XAML
• Like any other resource, declare instance
  in resources; UserControl.Resources in
  demo
• Need namespace reference




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Referencing the Type
Converter
• Need way to refer to type converter in
  XAML
• Like any other resource, declare instance
  in resources; UserControl.Resources in
  demo
• Need namespace reference
  • xmlns:local="clr-namespace:Binding"




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Referencing the Type
Converter
• Need way to refer to type converter in
  XAML
• Like any other resource, declare instance
  in resources; UserControl.Resources in
  demo
• Need namespace reference
  • xmlns:local="clr-namespace:Binding"
• Then, within UserControl.Resources:



          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Referencing the Type
Converter
• Need way to refer to type converter in
  XAML
• Like any other resource, declare instance
  in resources; UserControl.Resources in
  demo
• Need namespace reference
  • xmlns:local="clr-namespace:Binding"
• Then, within UserControl.Resources:
  • <UserControl.Resources>
      <local:IntegerToThicknessConverter
        x:Key="thicknessConverter" />

          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Using the Type Converter




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Using the Type Converter
• Add a setting in Binding markup
  extension




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Using the Type Converter
• Add a setting in Binding markup
  extension
 <Border BorderThickness="{Binding
    ElementName=ThicknessComboBox,
    Path=SelectedValue,
    Converter={StaticResource thicknessConverter}}"
    BorderBrush="Black"
    Margin="5">




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Using the Visual Studio
Designer




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Using the Visual Studio
Designer
• DEMO




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda




     Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Agenda
• Introducing Binding




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• Introducing Binding
• Working with Type Converters




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• Introducing Binding
• Working with Type Converters
• Binding Lists and Data Templates




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Agenda
•   Introducing Binding
•   Working with Type Converters
•   Binding Lists and Data Templates
•   Using Binding and Data Templates




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Binding Lists and Data
Templates




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Binding Lists and Data
Templates
• Common use of binding: Display data
  in lists




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Binding Lists and Data
Templates
• Common use of binding: Display data
  in lists
  • ComboBox/ListBox




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Binding Lists and Data
Templates
• Common use of binding: Display data
  in lists
  • ComboBox/ListBox
• Whether retrieving data from database,
  or using a collection in memory




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Binding Lists and Data
Templates
• Common use of binding: Display data
  in lists
  • ComboBox/ListBox
• Whether retrieving data from database,
  or using a collection in memory
  • Useful to be able to display data




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Binding Lists and Data
Templates
• Common use of binding: Display data
  in lists
  • ComboBox/ListBox
• Whether retrieving data from database,
  or using a collection in memory
  • Useful to be able to display data
• Imagine scenario:


          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Binding Lists and Data
Templates
• Common use of binding: Display data
  in lists
  • ComboBox/ListBox
• Whether retrieving data from database,
  or using a collection in memory
  • Useful to be able to display data
• Imagine scenario:
  • Want to display list box with numbers

          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Binding Lists and Data
Templates
• Common use of binding: Display data
  in lists
  • ComboBox/ListBox
• Whether retrieving data from database,
  or using a collection in memory
  • Useful to be able to display data
• Imagine scenario:
  • Want to display list box with numbers
  • Also display bar with magnitude
          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Binding Lists and Data
Templates
• Common use of binding: Display data
  in lists
  • ComboBox/ListBox
• Whether retrieving data from database,
  or using a collection in memory
  • Useful to be able to display data
• Imagine scenario:
  • Want to display list box with numbers
  • Also display bar with magnitude
          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Filling the List/Displaying the
Data




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Filling the List/Displaying the
Data
• DEMO




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Adding a Data Template




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Adding a Data Template
• Given ListBox displaying numbers




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Adding a Data Template
• Given ListBox displaying numbers
  • Next task is to modify layout for each item in list




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Adding a Data Template
• Given ListBox displaying numbers
  • Next task is to modify layout for each item in list
• XML Data Template designed just for this




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Adding a Data Template
• Given ListBox displaying numbers
  • Next task is to modify layout for each item in list
• XML Data Template designed just for this
  • Allows you to pass one row of data at a time
    through custom format, as control renders output




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Adding a Data Template
• Given ListBox displaying numbers
  • Next task is to modify layout for each item in list
• XML Data Template designed just for this
  • Allows you to pass one row of data at a time
    through custom format, as control renders output
• Data template simply a chunk of XAML
  markup




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Adding a Data Template
• Given ListBox displaying numbers
  • Next task is to modify layout for each item in list
• XML Data Template designed just for this
  • Allows you to pass one row of data at a time
    through custom format, as control renders output
• Data template simply a chunk of XAML
  markup
  • Defines how each row should be displayed




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Adding a Data Template
• Given ListBox displaying numbers
  • Next task is to modify layout for each item in list
• XML Data Template designed just for this
  • Allows you to pass one row of data at a time
    through custom format, as control renders output
• Data template simply a chunk of XAML
  markup
  • Defines how each row should be displayed
  • Can contain any markup you like




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Adding a Data Template
• Given ListBox displaying numbers
  • Next task is to modify layout for each item in list
• XML Data Template designed just for this
  • Allows you to pass one row of data at a time
    through custom format, as control renders output
• Data template simply a chunk of XAML
  markup
  • Defines how each row should be displayed
  • Can contain any markup you like
     • Include at least one Binding markup extension




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Adding a Data Template
• Given ListBox displaying numbers
  • Next task is to modify layout for each item in list
• XML Data Template designed just for this
  • Allows you to pass one row of data at a time
    through custom format, as control renders output
• Data template simply a chunk of XAML
  markup
  • Defines how each row should be displayed
  • Can contain any markup you like
     • Include at least one Binding markup extension
     • Otherwise, pretty dull



             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Agenda




     Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Agenda
• Introducing Binding




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• Introducing Binding
• Working with Type Converters




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• Introducing Binding
• Working with Type Converters
• Binding Lists and Data Templates




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
•   Introducing Binding
•   Working with Type Converters
•   Binding Lists and Data Templates
•   Using Binding and Data Templates




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Using Binding and Data
Templates




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Using Binding and Data
Templates
 • A final scenario that uses binding and
   data templates




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Using Binding and Data
Templates
 • A final scenario that uses binding and
   data templates
 • Display list of color names and color
   “swatches”




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Using Binding and Data
Templates
 • A final scenario that uses binding and
   data templates
 • Display list of color names and color
   “swatches”
 • Select a color and set background color
   for border



          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Learn More!




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Learn More!
• This is an excerpt from a larger course. Visit
  www.learnnowonline.com for the full details!




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Learn More!
• This is an excerpt from a larger course. Visit
  www.learnnowonline.com for the full details!




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Learn More!
• This is an excerpt from a larger course. Visit
  www.learnnowonline.com for the full details!


• Learn more about WPF on SlideShare:




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Learn More!
• This is an excerpt from a larger course. Visit
  www.learnnowonline.com for the full details!


• Learn more about WPF on SlideShare:
   Intro to Windows Presentation Foundation
    (WPF)




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Learn More!
• This is an excerpt from a larger course. Visit
  www.learnnowonline.com for the full details!


• Learn more about WPF on SlideShare:
   Intro to Windows Presentation Foundation
    (WPF)
   WPF: Advanced Controls




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company

Weitere ähnliche Inhalte

Was ist angesagt?

IMMERSE 2016 Introducing content fragments
IMMERSE 2016 Introducing content fragmentsIMMERSE 2016 Introducing content fragments
IMMERSE 2016 Introducing content fragmentsAdobeMarketingCloud
 
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...Gáspár Nagy
 
IMMERSE 2016 IST Mark Szulc Keynote
IMMERSE 2016 IST Mark Szulc KeynoteIMMERSE 2016 IST Mark Szulc Keynote
IMMERSE 2016 IST Mark Szulc KeynoteAdobeMarketingCloud
 
Dynamic Components using Single-Page-Application Concepts in AEM/CQ
Dynamic Components using Single-Page-Application Concepts in AEM/CQDynamic Components using Single-Page-Application Concepts in AEM/CQ
Dynamic Components using Single-Page-Application Concepts in AEM/CQNetcetera
 
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIOJumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIOJosh Cypher
 
Evolve13 cq-commerce-framework
Evolve13 cq-commerce-frameworkEvolve13 cq-commerce-framework
Evolve13 cq-commerce-frameworkPaolo Mottadelli
 
AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Chica...
AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Chica...AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Chica...
AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Chica...Amazon Web Services
 
Adobe AEM - Global SEO
Adobe AEM - Global SEOAdobe AEM - Global SEO
Adobe AEM - Global SEOEli Schwartz
 
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...Gáspár Nagy
 
Business Applications Integration In The Cloud
Business Applications Integration In The CloudBusiness Applications Integration In The Cloud
Business Applications Integration In The CloudAnna Brzezińska
 
API Technical Writing
API Technical WritingAPI Technical Writing
API Technical WritingSarah Maddox
 
JCR, Sling or AEM? Which API should I use and when?
JCR, Sling or AEM? Which API should I use and when?JCR, Sling or AEM? Which API should I use and when?
JCR, Sling or AEM? Which API should I use and when?connectwebex
 
Redefining Technical SEO - Paul Shapiro at MozCon 2019
Redefining Technical SEO - Paul Shapiro at MozCon 2019Redefining Technical SEO - Paul Shapiro at MozCon 2019
Redefining Technical SEO - Paul Shapiro at MozCon 2019Catalyst
 
Integrating with Adobe Marketing Cloud - Summit 2014
Integrating with Adobe Marketing Cloud - Summit 2014Integrating with Adobe Marketing Cloud - Summit 2014
Integrating with Adobe Marketing Cloud - Summit 2014Paolo Mottadelli
 
Salesforce Certifications:Explained
Salesforce Certifications:ExplainedSalesforce Certifications:Explained
Salesforce Certifications:ExplainedAtul Gupta(8X)
 
Use Amazon Rekognition to Build a Facial Recognition System
Use Amazon Rekognition to Build a Facial Recognition SystemUse Amazon Rekognition to Build a Facial Recognition System
Use Amazon Rekognition to Build a Facial Recognition SystemAmazon Web Services
 

Was ist angesagt? (20)

IMMERSE 2016 Introducing content fragments
IMMERSE 2016 Introducing content fragmentsIMMERSE 2016 Introducing content fragments
IMMERSE 2016 Introducing content fragments
 
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
 
IMMERSE 2016 IST Mark Szulc Keynote
IMMERSE 2016 IST Mark Szulc KeynoteIMMERSE 2016 IST Mark Szulc Keynote
IMMERSE 2016 IST Mark Szulc Keynote
 
Dynamic Components using Single-Page-Application Concepts in AEM/CQ
Dynamic Components using Single-Page-Application Concepts in AEM/CQDynamic Components using Single-Page-Application Concepts in AEM/CQ
Dynamic Components using Single-Page-Application Concepts in AEM/CQ
 
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIOJumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
 
Evolve13 cq-commerce-framework
Evolve13 cq-commerce-frameworkEvolve13 cq-commerce-framework
Evolve13 cq-commerce-framework
 
AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Chica...
AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Chica...AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Chica...
AWS DeepLens Workshop: Building Computer Vision Applications - BDA201 - Chica...
 
Adobe AEM - Global SEO
Adobe AEM - Global SEOAdobe AEM - Global SEO
Adobe AEM - Global SEO
 
ADA CORE- 2.0
ADA CORE- 2.0ADA CORE- 2.0
ADA CORE- 2.0
 
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
 
Business Applications Integration In The Cloud
Business Applications Integration In The CloudBusiness Applications Integration In The Cloud
Business Applications Integration In The Cloud
 
05 managing transactions
05   managing transactions05   managing transactions
05 managing transactions
 
API Technical Writing
API Technical WritingAPI Technical Writing
API Technical Writing
 
JCR, Sling or AEM? Which API should I use and when?
JCR, Sling or AEM? Which API should I use and when?JCR, Sling or AEM? Which API should I use and when?
JCR, Sling or AEM? Which API should I use and when?
 
Startup Pitching and Mobile App Startup
Startup Pitching and Mobile App StartupStartup Pitching and Mobile App Startup
Startup Pitching and Mobile App Startup
 
Redefining Technical SEO - Paul Shapiro at MozCon 2019
Redefining Technical SEO - Paul Shapiro at MozCon 2019Redefining Technical SEO - Paul Shapiro at MozCon 2019
Redefining Technical SEO - Paul Shapiro at MozCon 2019
 
Integrating with Adobe Marketing Cloud - Summit 2014
Integrating with Adobe Marketing Cloud - Summit 2014Integrating with Adobe Marketing Cloud - Summit 2014
Integrating with Adobe Marketing Cloud - Summit 2014
 
Salesforce Certifications:Explained
Salesforce Certifications:ExplainedSalesforce Certifications:Explained
Salesforce Certifications:Explained
 
Ember.js firebase HTML5 NYC
Ember.js firebase HTML5 NYCEmber.js firebase HTML5 NYC
Ember.js firebase HTML5 NYC
 
Use Amazon Rekognition to Build a Facial Recognition System
Use Amazon Rekognition to Build a Facial Recognition SystemUse Amazon Rekognition to Build a Facial Recognition System
Use Amazon Rekognition to Build a Facial Recognition System
 

Ähnlich wie WPF Binding

WPF: Working with Data
WPF: Working with DataWPF: Working with Data
WPF: Working with DataLearnNowOnline
 
.NET Variables and Data Types
.NET Variables and Data Types.NET Variables and Data Types
.NET Variables and Data TypesLearnNowOnline
 
.Net branching and flow control
.Net branching and flow control.Net branching and flow control
.Net branching and flow controlLearnNowOnline
 
SharePoint Document Management
SharePoint Document ManagementSharePoint Document Management
SharePoint Document ManagementLearnNowOnline
 
Object oriented techniques
Object oriented techniquesObject oriented techniques
Object oriented techniquesLearnNowOnline
 
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5LearnNowOnline
 
Managing site collections
Managing site collectionsManaging site collections
Managing site collectionsLearnNowOnline
 
Bring a Web Page Alive with jQuery
Bring a Web Page Alive with jQueryBring a Web Page Alive with jQuery
Bring a Web Page Alive with jQueryLearnNowOnline
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity FrameworkLearnNowOnline
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingLearnNowOnline
 
Working with Controllers and Actions in MVC
Working with Controllers and Actions in MVCWorking with Controllers and Actions in MVC
Working with Controllers and Actions in MVCLearnNowOnline
 
KnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCKnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCLearnNowOnline
 
JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsLearnNowOnline
 
Creating a User Interface
Creating a User InterfaceCreating a User Interface
Creating a User InterfaceLearnNowOnline
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCLearnNowOnline
 

Ähnlich wie WPF Binding (20)

WPF: Working with Data
WPF: Working with DataWPF: Working with Data
WPF: Working with Data
 
The Entity Data Model
The Entity Data ModelThe Entity Data Model
The Entity Data Model
 
.NET Variables and Data Types
.NET Variables and Data Types.NET Variables and Data Types
.NET Variables and Data Types
 
.Net branching and flow control
.Net branching and flow control.Net branching and flow control
.Net branching and flow control
 
SharePoint Document Management
SharePoint Document ManagementSharePoint Document Management
SharePoint Document Management
 
Introducing LINQ
Introducing LINQIntroducing LINQ
Introducing LINQ
 
Object oriented techniques
Object oriented techniquesObject oriented techniques
Object oriented techniques
 
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
 
Managing site collections
Managing site collectionsManaging site collections
Managing site collections
 
Bring a Web Page Alive with jQuery
Bring a Web Page Alive with jQueryBring a Web Page Alive with jQuery
Bring a Web Page Alive with jQuery
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity Framework
 
Web API Basics
Web API BasicsWeb API Basics
Web API Basics
 
SQL Server: Security
SQL Server: SecuritySQL Server: Security
SQL Server: Security
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programming
 
Working with Controllers and Actions in MVC
Working with Controllers and Actions in MVCWorking with Controllers and Actions in MVC
Working with Controllers and Actions in MVC
 
KnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCKnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVC
 
JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and Expressions
 
Generics
GenericsGenerics
Generics
 
Creating a User Interface
Creating a User InterfaceCreating a User Interface
Creating a User Interface
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 

Mehr von LearnNowOnline

Windows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesWindows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesLearnNowOnline
 
SQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionSQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionLearnNowOnline
 
New in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDENew in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDELearnNowOnline
 
SharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathSharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathLearnNowOnline
 
Sql 2012 development and programming
Sql 2012  development and programmingSql 2012  development and programming
Sql 2012 development and programmingLearnNowOnline
 
Expression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignExpression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignLearnNowOnline
 

Mehr von LearnNowOnline (7)

Windows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesWindows 8: Shapes and Geometries
Windows 8: Shapes and Geometries
 
SQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionSQL: Permissions and Data Protection
SQL: Permissions and Data Protection
 
New in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDENew in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDE
 
A tour of SQL Server
A tour of SQL ServerA tour of SQL Server
A tour of SQL Server
 
SharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathSharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPath
 
Sql 2012 development and programming
Sql 2012  development and programmingSql 2012  development and programming
Sql 2012 development and programming
 
Expression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignExpression Blend Motion & Interaction Design
Expression Blend Motion & Interaction Design
 

Kürzlich hochgeladen

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
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
 
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
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
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
 
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
 
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
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
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
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 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!
 
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
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
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
 
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
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
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
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

WPF Binding

  • 1. WPF: Binding Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 2. Objectives Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 3. Objectives • Learn to use Binding objects to bind data sources and targets Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 4. Objectives • Learn to use Binding objects to bind data sources and targets • Add data converters to manage conversion during the binding process Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 5. Objectives • Learn to use Binding objects to bind data sources and targets • Add data converters to manage conversion during the binding process • Use data templates to modify the layout of bound data in lists Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 6. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 7. Agenda • Introducing Binding Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 8. Agenda • Introducing Binding • Working with Type Converters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 9. Agenda • Introducing Binding • Working with Type Converters • Binding Lists and Data Templates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 10. Agenda • Introducing Binding • Working with Type Converters • Binding Lists and Data Templates • Using Binding and Data Templates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 11. Introducing Binding Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 12. Introducing Binding • Often need to update one element with information from another Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 13. Introducing Binding • Often need to update one element with information from another • Display information from collection of objects in list, or combo box Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 14. Introducing Binding • Often need to update one element with information from another • Display information from collection of objects in list, or combo box • Or need to work with data from database Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 15. Introducing Binding • Often need to update one element with information from another • Display information from collection of objects in list, or combo box • Or need to work with data from database • In all these cases Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 16. Introducing Binding • Often need to update one element with information from another • Display information from collection of objects in list, or combo box • Or need to work with data from database • In all these cases • Simplest solution is to bind data from binding source to target Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 17. Introducing Binding • Often need to update one element with information from another • Display information from collection of objects in list, or combo box • Or need to work with data from database • In all these cases • Simplest solution is to bind data from binding source to target • In other words—need some way to perform binding Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 18. When to Use Binding? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 19. When to Use Binding? • Display in the number of characters in a text box, in a TextBlock control Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 20. When to Use Binding? • Display in the number of characters in a text box, in a TextBlock control • Display the value of Slider control in a TextBlock Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 21. When to Use Binding? • Display in the number of characters in a text box, in a TextBlock control • Display the value of Slider control in a TextBlock • Display list of customers in ListBox Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 22. When to Use Binding? • Display in the number of characters in a text box, in a TextBlock control • Display the value of Slider control in a TextBlock • Display list of customers in ListBox • Display customer’s photo in Image control Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 23. When to Use Binding? • Display in the number of characters in a text box, in a TextBlock control • Display the value of Slider control in a TextBlock • Display list of customers in ListBox • Display customer’s photo in Image control • Display and edit customer’s name in TextBox Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 24. Connecting Sources and Targets Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 25. Connecting Sources and Targets • Every time you use binding Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 26. Connecting Sources and Targets • Every time you use binding • Must supply source for data, and target Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 27. Connecting Sources and Targets • Every time you use binding • Must supply source for data, and target • Normally, target is dependency property of some user interface element Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 28. Connecting Sources and Targets • Every time you use binding • Must supply source for data, and target • Normally, target is dependency property of some user interface element Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 29. Connecting Sources and Targets Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 30. Connecting Sources and Targets • Binding source can be any property of any CLR object Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 31. Connecting Sources and Targets • Binding source can be any property of any CLR object • Binding object connects source to binding target Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 32. Connecting Sources and Targets • Binding source can be any property of any CLR object • Binding object connects source to binding target • Must be dependency property of some FrameworkElement object Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 33. Under the Hood Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 34. Under the Hood • When using binding in XAML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 35. Under the Hood • When using binding in XAML • Create instance of Binding class, setting various properties that affect its behavior Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 36. Under the Hood • When using binding in XAML • Create instance of Binding class, setting various properties that affect its behavior • XAML provides binding markup extension Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 37. Under the Hood • When using binding in XAML • Create instance of Binding class, setting various properties that affect its behavior • XAML provides binding markup extension • Hides this fact, but still working with Binding object Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 38. Under the Hood • When using binding in XAML • Create instance of Binding class, setting various properties that affect its behavior • XAML provides binding markup extension • Hides this fact, but still working with Binding object • Completely transparent if you create Binding object in code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 39. Under the Hood • When using binding in XAML • Create instance of Binding class, setting various properties that affect its behavior • XAML provides binding markup extension • Hides this fact, but still working with Binding object • Completely transparent if you create Binding object in code • Can set Mode property of Binding to control direction of data flow (one/two Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 40. Value Converters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 41. Value Converters • Value Converter block in figure represents instance of class that implements System.Windows.Data.IValueConverter interface Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 42. Value Converters • Value Converter block in figure represents instance of class that implements System.Windows.Data.IValueConverter interface • Doing binding declaratively, in XAML, often requires value converter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 43. Value Converters • Value Converter block in figure represents instance of class that implements System.Windows.Data.IValueConverter interface • Doing binding declaratively, in XAML, often requires value converter • Select a customer from a ListBox, display combined FirstName and LastName fields in TextBlock Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 44. Value Converters • Value Converter block in figure represents instance of class that implements System.Windows.Data.IValueConverter interface • Doing binding declaratively, in XAML, often requires value converter • Select a customer from a ListBox, display combined FirstName and LastName fields in TextBlock • Select an integer, bind to BorderThickness of Border Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 45. Value Converters • Value Converter block in figure represents instance of class that implements System.Windows.Data.IValueConverter interface • Doing binding declaratively, in XAML, often requires value converter • Select a customer from a ListBox, display combined FirstName and LastName fields in TextBlock • Select an integer, bind to BorderThickness of Border • Can’t bind directly—BorderThickness is a Thickness Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 46. A Few Simple Examples Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 47. A Few Simple Examples • DEMO Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 48. Binding Details Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 49. Binding Details • Standard Binding markup extension includes ElementName and Path attributes: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 50. Binding Details • Standard Binding markup extension includes ElementName and Path attributes: • Text= "{Binding ElementName=DemoSlider, Path=Value}" Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 51. Binding Details • Standard Binding markup extension includes ElementName and Path attributes: • Text= "{Binding ElementName=DemoSlider, Path=Value}" • Path attribute not required: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 52. Binding Details • Standard Binding markup extension includes ElementName and Path attributes: • Text= "{Binding ElementName=DemoSlider, Path=Value}" • Path attribute not required: • Text="{Binding Value, ElementName=DemoSlider }" Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 53. Binding Details Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 54. Binding Details • Path property can refer to property, or property of a property, or indexed property Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 55. Binding Details • Path property can refer to property, or property of a property, or indexed property • Need to refer to an attached property? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 56. Binding Details • Path property can refer to property, or property of a property, or indexed property • Need to refer to an attached property? • Grid.Row, for example Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 57. Binding Details • Path property can refer to property, or property of a property, or indexed property • Need to refer to an attached property? • Grid.Row, for example • Set Path property to (Grid.Row) (in parentheses) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 58. Binding Details Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 59. Binding Details • Binding Markup extension shortcut for child element syntax: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 60. Binding Details • Binding Markup extension shortcut for child element syntax: <TextBox Width="40" Name="DemoTextBox" Height="23"> <TextBox.Text> <Binding ElementName="DemoSlider" Path="Value" /> </TextBox.Text> </TextBox> Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 61. Setting the Binding Mode Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 62. Setting the Binding Mode • In previous demo, data moves from Slider to TextBox Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 63. Setting the Binding Mode • In previous demo, data moves from Slider to TextBox • Changes you make in TextBox have no effect on slider Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 64. Setting the Binding Mode • In previous demo, data moves from Slider to TextBox • Changes you make in TextBox have no effect on slider • Binding is one-way: Data moves in one direction Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 65. Setting the Binding Mode • In previous demo, data moves from Slider to TextBox • Changes you make in TextBox have no effect on slider • Binding is one-way: Data moves in one direction • Set Mode property of Binding to change Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 66. Setting the Binding Mode • In previous demo, data moves from Slider to TextBox • Changes you make in TextBox have no effect on slider • Binding is one-way: Data moves in one direction • Set Mode property of Binding to change • Set Mode to: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 67. Setting the Binding Mode • In previous demo, data moves from Slider to TextBox • Changes you make in TextBox have no effect on slider • Binding is one-way: Data moves in one direction • Set Mode property of Binding to change • Set Mode to: • OneTime Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 68. Additional Binding Mode Options (WPF) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 69. Additional Binding Mode Options (WPF) • Can also set Mode to: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 70. Additional Binding Mode Options (WPF) • Can also set Mode to: • OneWayToSource Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 71. Additional Binding Mode Options (WPF) • Can also set Mode to: • OneWayToSource • Default Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 72. DEMO Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 73. DEMO • Two-way binding, SimpleBinding3 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 74. A Simple Example Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 75. A Simple Example • Enter text into TextBox, update TextBlock with length of the text Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 76. A Simple Example • Enter text into TextBox, update TextBlock with length of the text • Could react to TextChanged event of TextBox Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 77. A Simple Example • Enter text into TextBox, update TextBlock with length of the text • Could react to TextChanged event of TextBox • Better: Bind Text property of TextBlock to Text.Length property of TextBox Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 78. A Simple Example • Enter text into TextBox, update TextBlock with length of the text • Could react to TextChanged event of TextBox • Better: Bind Text property of TextBlock to Text.Length property of TextBox • Points out that binding can use expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 79. DEMO Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 80. DEMO • SimpleBinding4 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 81. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 82. Agenda • Introducing Binding Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 83. Agenda • Introducing Binding • Working with Type Converters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 84. Agenda • Introducing Binding • Working with Type Converters • Binding Lists and Data Templates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 85. Agenda • Introducing Binding • Working with Type Converters • Binding Lists and Data Templates • Using Binding and Data Templates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 86. Working with Type Converters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 87. Working with Type Converters • Every example so far moved data from source to target without modifying data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 88. Working with Type Converters • Every example so far moved data from source to target without modifying data • Or relied on built-in type converters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 89. Working with Type Converters • Every example so far moved data from source to target without modifying data • Or relied on built-in type converters • What happens when source to target requires conversion? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 90. Working with Type Converters • Every example so far moved data from source to target without modifying data • Or relied on built-in type converters • What happens when source to target requires conversion? • You have color name, want to apply to a property that requires a brush? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 91. Working with Type Converters • Every example so far moved data from source to target without modifying data • Or relied on built-in type converters • What happens when source to target requires conversion? • You have color name, want to apply to a property that requires a brush? • How can you convert during the binding process? More @ http://www.learnnowonline.com Learn Copyright © by Application Developers Training Company
  • 92. Type Converters to the Rescue Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 93. Type Converters to the Rescue • Type converter injects itself into the binding process Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 94. Type Converters to the Rescue • Type converter injects itself into the binding process • Converts data from the source to the target type Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 95. Type Converters to the Rescue • Type converter injects itself into the binding process • Converts data from the source to the target type • Must implement System.Windows.Data.IValueConverter interface Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 96. Type Converters to the Rescue • Type converter injects itself into the binding process • Converts data from the source to the target type • Must implement System.Windows.Data.IValueConverter interface • Two methods: Convert and ConvertBack Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 97. Type Converters to the Rescue • Type converter injects itself into the binding process • Converts data from the source to the target type • Must implement System.Windows.Data.IValueConverter interface • Two methods: Convert and ConvertBack • Simple to create converter, in general Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 98. Using the StringFormat Property Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 99. Using the StringFormat Property • Many conversions consist of formatting a string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 100. Using the StringFormat Property • Many conversions consist of formatting a string • Could create a type converter; not necessary Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 101. Using the StringFormat Property • Many conversions consist of formatting a string • Could create a type converter; not necessary • Convert a value into a formatted string? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 102. Using the StringFormat Property • Many conversions consist of formatting a string • Could create a type converter; not necessary • Convert a value into a formatted string? • Can often use StringFormat property Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 103. DEMO Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 104. DEMO • BindingWithConverter1 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 105. StringFormat Details Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 106. StringFormat Details • Simplest format: StringFormat=0.0 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 107. StringFormat Details • Simplest format: StringFormat=0.0 • Can also specify numeric formatting string, as if calling String.Format method: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 108. StringFormat Details • Simplest format: StringFormat=0.0 • Can also specify numeric formatting string, as if calling String.Format method: • StringFormat={}{0:F1} Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 109. StringFormat Details • Simplest format: StringFormat=0.0 • Can also specify numeric formatting string, as if calling String.Format method: • StringFormat={}{0:F1} • {} “escapes” formatting string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 110. StringFormat Details • Simplest format: StringFormat=0.0 • Can also specify numeric formatting string, as if calling String.Format method: • StringFormat={}{0:F1} • {} “escapes” formatting string • Include text, don’t need escape Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 111. StringFormat Details • Simplest format: StringFormat=0.0 • Can also specify numeric formatting string, as if calling String.Format method: • StringFormat={}{0:F1} • {} “escapes” formatting string • Include text, don’t need escape • StringFormat=The value is: {0:F1} Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 112. StringFormat Details • Simplest format: StringFormat=0.0 • Can also specify numeric formatting string, as if calling String.Format method: • StringFormat={}{0:F1} • {} “escapes” formatting string • Include text, don’t need escape • StringFormat=The value is: {0:F1} • More tricks: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 113. StringFormat Details • Simplest format: StringFormat=0.0 • Can also specify numeric formatting string, as if calling String.Format method: • StringFormat={}{0:F1} • {} “escapes” formatting string • Include text, don’t need escape • StringFormat=The value is: {0:F1} • More tricks: • Can bind to multiple elements using MultiBinding Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 114. StringFormat Details • Simplest format: StringFormat=0.0 • Can also specify numeric formatting string, as if calling String.Format method: • StringFormat={}{0:F1} • {} “escapes” formatting string • Include text, don’t need escape • StringFormat=The value is: {0:F1} • More tricks: • Can bind to multiple elements using MultiBinding • Check it out! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 115. Using a Type Converter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 116. Using a Type Converter • Sometimes, StringFormat can’t do the job Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 117. Using a Type Converter • Sometimes, StringFormat can’t do the job • Will need to run code as data transfers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 118. Using a Type Converter • Sometimes, StringFormat can’t do the job • Will need to run code as data transfers • Need a type converter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 119. Using a Type Converter • Sometimes, StringFormat can’t do the job • Will need to run code as data transfers • Need a type converter • Determine source and target data types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 120. Using a Type Converter • Sometimes, StringFormat can’t do the job • Will need to run code as data transfers • Need a type converter • Determine source and target data types • Write code to perform the conversion Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 121. Using a Type Converter • Sometimes, StringFormat can’t do the job • Will need to run code as data transfers • Need a type converter • Determine source and target data types • Write code to perform the conversion • Perhaps write code to convert back (for two-way binding) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 122. Using a Type Converter • Sometimes, StringFormat can’t do the job • Will need to run code as data transfers • Need a type converter • Determine source and target data types • Write code to perform the conversion • Perhaps write code to convert back (for two-way binding) • Sample binds integer from combo box to BorderThickness property Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 123. Using a Type Converter • Sometimes, StringFormat can’t do the job • Will need to run code as data transfers • Need a type converter • Determine source and target data types • Write code to perform the conversion • Perhaps write code to convert back (for two-way binding) • Sample binds integer from combo box to BorderThickness property • What’s the problem? Thickness structure has four Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 124. Creating the Type Converter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 125. Creating the Type Converter • Attempt to bind SelectedValue of ComboBox to BorderThickness of Border, and fails Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 126. Creating the Type Converter • Attempt to bind SelectedValue of ComboBox to BorderThickness of Border, and fails • Need type (or value) converter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 127. Converters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 128. Converters • Implement IValueConverter interface Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 129. Converters • Implement IValueConverter interface • Requires Convert and ConvertBack methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 130. Converters • Implement IValueConverter interface • Requires Convert and ConvertBack methods • Parameters: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 131. Converters • Implement IValueConverter interface • Requires Convert and ConvertBack methods • Parameters: • value (System.Object) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 132. Converters • Implement IValueConverter interface • Requires Convert and ConvertBack methods • Parameters: • value (System.Object) • targetType (System.Type) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 133. Converters • Implement IValueConverter interface • Requires Convert and ConvertBack methods • Parameters: • value (System.Object) • targetType (System.Type) • parameter (System.Object) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 134. Converters • Implement IValueConverter interface • Requires Convert and ConvertBack methods • Parameters: • value (System.Object) • targetType (System.Type) • parameter (System.Object) • culture (System.Globalization.Culture) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 135. Converter Warning Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 136. Converter Warning • Converter doesn’t trap exceptions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 137. Converter Warning • Converter doesn’t trap exceptions • Treated as runtime errors Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 138. Converter Warning • Converter doesn’t trap exceptions • Treated as runtime errors • You must trap and handle all runtime errors Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 139. Converter Warning • Converter doesn’t trap exceptions • Treated as runtime errors • You must trap and handle all runtime errors • Return DependencyProperty.UnsetValue on error Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 140. Converter Warning • Converter doesn’t trap exceptions • Treated as runtime errors • You must trap and handle all runtime errors • Return DependencyProperty.UnsetValue on error • Not handled in this simple demo Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 141. Converter Warning • Converter doesn’t trap exceptions • Treated as runtime errors • You must trap and handle all runtime errors • Return DependencyProperty.UnsetValue on error • Not handled in this simple demo • Worth considering! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 142. DEMO Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 143. DEMO • IntegerToThicknessConverter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 144. Referencing the Type Converter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 145. Referencing the Type Converter • Need way to refer to type converter in XAML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 146. Referencing the Type Converter • Need way to refer to type converter in XAML • Like any other resource, declare instance in resources; UserControl.Resources in demo Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 147. Referencing the Type Converter • Need way to refer to type converter in XAML • Like any other resource, declare instance in resources; UserControl.Resources in demo • Need namespace reference Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 148. Referencing the Type Converter • Need way to refer to type converter in XAML • Like any other resource, declare instance in resources; UserControl.Resources in demo • Need namespace reference • xmlns:local="clr-namespace:Binding" Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 149. Referencing the Type Converter • Need way to refer to type converter in XAML • Like any other resource, declare instance in resources; UserControl.Resources in demo • Need namespace reference • xmlns:local="clr-namespace:Binding" • Then, within UserControl.Resources: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 150. Referencing the Type Converter • Need way to refer to type converter in XAML • Like any other resource, declare instance in resources; UserControl.Resources in demo • Need namespace reference • xmlns:local="clr-namespace:Binding" • Then, within UserControl.Resources: • <UserControl.Resources> <local:IntegerToThicknessConverter x:Key="thicknessConverter" /> Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 151. Using the Type Converter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 152. Using the Type Converter • Add a setting in Binding markup extension Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 153. Using the Type Converter • Add a setting in Binding markup extension <Border BorderThickness="{Binding ElementName=ThicknessComboBox, Path=SelectedValue, Converter={StaticResource thicknessConverter}}" BorderBrush="Black" Margin="5"> Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 154. Using the Visual Studio Designer Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 155. Using the Visual Studio Designer • DEMO Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 156. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 157. Agenda • Introducing Binding Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 158. Agenda • Introducing Binding • Working with Type Converters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 159. Agenda • Introducing Binding • Working with Type Converters • Binding Lists and Data Templates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 160. Agenda • Introducing Binding • Working with Type Converters • Binding Lists and Data Templates • Using Binding and Data Templates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 161. Binding Lists and Data Templates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 162. Binding Lists and Data Templates • Common use of binding: Display data in lists Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 163. Binding Lists and Data Templates • Common use of binding: Display data in lists • ComboBox/ListBox Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 164. Binding Lists and Data Templates • Common use of binding: Display data in lists • ComboBox/ListBox • Whether retrieving data from database, or using a collection in memory Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 165. Binding Lists and Data Templates • Common use of binding: Display data in lists • ComboBox/ListBox • Whether retrieving data from database, or using a collection in memory • Useful to be able to display data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 166. Binding Lists and Data Templates • Common use of binding: Display data in lists • ComboBox/ListBox • Whether retrieving data from database, or using a collection in memory • Useful to be able to display data • Imagine scenario: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 167. Binding Lists and Data Templates • Common use of binding: Display data in lists • ComboBox/ListBox • Whether retrieving data from database, or using a collection in memory • Useful to be able to display data • Imagine scenario: • Want to display list box with numbers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 168. Binding Lists and Data Templates • Common use of binding: Display data in lists • ComboBox/ListBox • Whether retrieving data from database, or using a collection in memory • Useful to be able to display data • Imagine scenario: • Want to display list box with numbers • Also display bar with magnitude Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 169. Binding Lists and Data Templates • Common use of binding: Display data in lists • ComboBox/ListBox • Whether retrieving data from database, or using a collection in memory • Useful to be able to display data • Imagine scenario: • Want to display list box with numbers • Also display bar with magnitude Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 170. Filling the List/Displaying the Data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 171. Filling the List/Displaying the Data • DEMO Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 172. Adding a Data Template Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 173. Adding a Data Template • Given ListBox displaying numbers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 174. Adding a Data Template • Given ListBox displaying numbers • Next task is to modify layout for each item in list Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 175. Adding a Data Template • Given ListBox displaying numbers • Next task is to modify layout for each item in list • XML Data Template designed just for this Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 176. Adding a Data Template • Given ListBox displaying numbers • Next task is to modify layout for each item in list • XML Data Template designed just for this • Allows you to pass one row of data at a time through custom format, as control renders output Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 177. Adding a Data Template • Given ListBox displaying numbers • Next task is to modify layout for each item in list • XML Data Template designed just for this • Allows you to pass one row of data at a time through custom format, as control renders output • Data template simply a chunk of XAML markup Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 178. Adding a Data Template • Given ListBox displaying numbers • Next task is to modify layout for each item in list • XML Data Template designed just for this • Allows you to pass one row of data at a time through custom format, as control renders output • Data template simply a chunk of XAML markup • Defines how each row should be displayed Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 179. Adding a Data Template • Given ListBox displaying numbers • Next task is to modify layout for each item in list • XML Data Template designed just for this • Allows you to pass one row of data at a time through custom format, as control renders output • Data template simply a chunk of XAML markup • Defines how each row should be displayed • Can contain any markup you like Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 180. Adding a Data Template • Given ListBox displaying numbers • Next task is to modify layout for each item in list • XML Data Template designed just for this • Allows you to pass one row of data at a time through custom format, as control renders output • Data template simply a chunk of XAML markup • Defines how each row should be displayed • Can contain any markup you like • Include at least one Binding markup extension Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 181. Adding a Data Template • Given ListBox displaying numbers • Next task is to modify layout for each item in list • XML Data Template designed just for this • Allows you to pass one row of data at a time through custom format, as control renders output • Data template simply a chunk of XAML markup • Defines how each row should be displayed • Can contain any markup you like • Include at least one Binding markup extension • Otherwise, pretty dull Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 182. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 183. Agenda • Introducing Binding Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 184. Agenda • Introducing Binding • Working with Type Converters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 185. Agenda • Introducing Binding • Working with Type Converters • Binding Lists and Data Templates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 186. Agenda • Introducing Binding • Working with Type Converters • Binding Lists and Data Templates • Using Binding and Data Templates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 187. Using Binding and Data Templates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 188. Using Binding and Data Templates • A final scenario that uses binding and data templates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 189. Using Binding and Data Templates • A final scenario that uses binding and data templates • Display list of color names and color “swatches” Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 190. Using Binding and Data Templates • A final scenario that uses binding and data templates • Display list of color names and color “swatches” • Select a color and set background color for border Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 191. Learn More! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 192. Learn More! • This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 193. Learn More! • This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 194. Learn More! • This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! • Learn more about WPF on SlideShare: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 195. Learn More! • This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! • Learn more about WPF on SlideShare:  Intro to Windows Presentation Foundation (WPF) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 196. Learn More! • This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! • Learn more about WPF on SlideShare:  Intro to Windows Presentation Foundation (WPF)  WPF: Advanced Controls Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n
  152. \n
  153. \n
  154. \n
  155. \n
  156. \n
  157. \n
  158. \n
  159. \n
  160. \n
  161. \n
  162. DEMO: rest of section\n
  163. DEMO: rest of section\n
  164. DEMO: rest of section\n
  165. DEMO: rest of section\n
  166. DEMO: rest of section\n