Silverlight huh?
-
<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
-
<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
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
-
<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
-
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')?
It fails to set the
SelectedItem
correctly. I guess it's executing the properties in the order they are declared :confused: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
-
<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
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.
-
It fails to set the
SelectedItem
correctly. I guess it's executing the properties in the order they are declared :confused:Todd Smith
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
-
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.
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
-
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
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.