Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. Silverlight huh?

Silverlight huh?

Scheduled Pinned Locked Moved Clever Code
9 Posts 6 Posters 25 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Todd Smith
    wrote on last edited by
    #1

    <ComboBox Loaded="ComboBox_Loaded"
    ItemsSource="{Binding Tags}"
    SelectedItem="{Binding Path=SelectedTag, Mode=TwoWay}" />

    <ComboBox Loaded="ComboBox_Loaded"
    SelectedItem="{Binding Path=SelectedTag, Mode=TwoWay}"
    ItemsSource="{Binding Tags}" />

    Can you see the difference between these two statements? Would you guess that they actually result in different behavior?

    Todd Smith

    D 0 P 3 Replies Last reply
    0
    • T Todd Smith

      <ComboBox Loaded="ComboBox_Loaded"
      ItemsSource="{Binding Tags}"
      SelectedItem="{Binding Path=SelectedTag, Mode=TwoWay}" />

      <ComboBox Loaded="ComboBox_Loaded"
      SelectedItem="{Binding Path=SelectedTag, Mode=TwoWay}"
      ItemsSource="{Binding Tags}" />

      Can you see the difference between these two statements? Would you guess that they actually result in different behavior?

      Todd Smith

      D Offline
      D Offline
      Dan Neely
      wrote on last edited by
      #2

      I'm almost afraid to ask, but is it the ordering, the indent, or the combination of the two.

      Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

      1 Reply Last reply
      0
      • T Todd Smith

        <ComboBox Loaded="ComboBox_Loaded"
        ItemsSource="{Binding Tags}"
        SelectedItem="{Binding Path=SelectedTag, Mode=TwoWay}" />

        <ComboBox Loaded="ComboBox_Loaded"
        SelectedItem="{Binding Path=SelectedTag, Mode=TwoWay}"
        ItemsSource="{Binding Tags}" />

        Can you see the difference between these two statements? Would you guess that they actually result in different behavior?

        Todd Smith

        0 Offline
        0 Offline
        0x3c0
        wrote on last edited by
        #3

        Never used Silverlight before, but does the bottom one not select the correct item? Or does the binding fail in some inexplicable way (something like 'Invalid data source')?

        T 1 Reply Last reply
        0
        • 0 0x3c0

          Never used Silverlight before, but does the bottom one not select the correct item? Or does the binding fail in some inexplicable way (something like 'Invalid data source')?

          T Offline
          T Offline
          Todd Smith
          wrote on last edited by
          #4

          It fails to set the SelectedItem correctly. I guess it's executing the properties in the order they are declared :confused:

          Todd Smith

          0 M 2 Replies Last reply
          0
          • T Todd Smith

            It fails to set the SelectedItem correctly. I guess it's executing the properties in the order they are declared :confused:

            Todd Smith

            0 Offline
            0 Offline
            0x3c0
            wrote on last edited by
            #5

            Makes sense. The XAML must be getting converted to code and compiled in the normal way. Icky, but predictable

            1 Reply Last reply
            0
            • T Todd Smith

              <ComboBox Loaded="ComboBox_Loaded"
              ItemsSource="{Binding Tags}"
              SelectedItem="{Binding Path=SelectedTag, Mode=TwoWay}" />

              <ComboBox Loaded="ComboBox_Loaded"
              SelectedItem="{Binding Path=SelectedTag, Mode=TwoWay}"
              ItemsSource="{Binding Tags}" />

              Can you see the difference between these two statements? Would you guess that they actually result in different behavior?

              Todd Smith

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Unlike WPF, Silverlight does not support Coersion, so the order that you do things is important. To understand coercion, consider a progress bar implementation; suppose you set the lower limit to 0, and the value to 10. Then set the upper limit to 5 - you'd expect the behaviour of the bar to either declare that the value was invalid or set it to the maximum allowed value (it's up to you what the value actually is) - that's coersion. Without it, what actually happens is that you have a progress bar value that's greater than the maximum allowed value.

              "WPF has many lovers. It's a veritable porn star!" - Josh Smith

              As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

              My blog | My articles | MoXAML PowerToys | Onyx

              P 1 Reply Last reply
              0
              • T Todd Smith

                It fails to set the SelectedItem correctly. I guess it's executing the properties in the order they are declared :confused:

                Todd Smith

                M Offline
                M Offline
                Marc Clifton
                wrote on last edited by
                #7

                Todd Smith wrote:

                I guess it's executing the properties in the order they are declared

                Well, keep in mind that it's not really the declarative portion, but the underlying behavior of the framework. If you wrote code to do this in both variations, you'd get the same results as you do with the declarative code. Marc

                Will work for food. Interacx

                1 Reply Last reply
                0
                • P Pete OHanlon

                  Unlike WPF, Silverlight does not support Coersion, so the order that you do things is important. To understand coercion, consider a progress bar implementation; suppose you set the lower limit to 0, and the value to 10. Then set the upper limit to 5 - you'd expect the behaviour of the bar to either declare that the value was invalid or set it to the maximum allowed value (it's up to you what the value actually is) - that's coersion. Without it, what actually happens is that you have a progress bar value that's greater than the maximum allowed value.

                  "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                  As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                  My blog | My articles | MoXAML PowerToys | Onyx

                  P Offline
                  P Offline
                  Philipp Sumi
                  wrote on last edited by
                  #8

                  Still, you have to deal with this issue in WPF as well: http://www.hardcodet.net/2009/01/xaml-binding-declaration-order-matters[^]

                  NetDrives - Open Source Network Share Management

                  P 1 Reply Last reply
                  0
                  • P Philipp Sumi

                    Still, you have to deal with this issue in WPF as well: http://www.hardcodet.net/2009/01/xaml-binding-declaration-order-matters[^]

                    NetDrives - Open Source Network Share Management

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    To a large extent, proper coercion on a DP takes care of this. The problem however, is that you have no indicator on a DP that coercion is implemented. It's purely optional, which can be a real PITA to sort. Good post though.

                    "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                    As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                    My blog | My articles | MoXAML PowerToys | Onyx

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups