wpf - Problems with data binding in ItemContainerStyle in Silverlight 3 -
I use data bindings in ListBox
for item code in itemcontainerStyle Unable to in Silverlight 3 This works fine in WPF. It is an example to showcase my problem. I really want to be tied to the IsSelected
property, but I think it is easy to follow this example.
I have ListBox
observable Items & gt;
of items
objects:
public class items {public string name {get; } Public brush color {get; }}
Here is the relevant Silverlight XAM:
& lt; ListBox x: name = "list box" itemsource = "{bound.}" & Gt; & Lt; ListBox.ItemContainerStyle & gt; & Lt; Style TargetType = "ListBoxItem" & gt; & Lt; Setter property = "background" value = "{binding color}" /> & Lt; / Style & gt; & Lt; /ListBox.ItemContainerStyle> & Lt; ListBox.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; TextBlock Text = "{binding name}" /> & Lt; / DataTemplate & gt; & Lt; /ListBox.ItemTemplate> & Lt; / ListBox & gt; TargetType = "{x: Type ListBoxItem}"
The same XML can be used in WPF if targetType = "ListBoxItem"
is TargetType = "{x: Type ListBoxItem}"
.
The WPF application will display items in the list box and the color of the color
object object will be determined according to the property color
. However, with Silverlight the application fails to be more and XamlParseException
text AG_E_RUNTIME_MANAGED_UNKNOWN_ERROR
. Being a stubborn man, I have also tried to remove XAMML, which instead of failing my own style:
binding binding = new binding ("color"); Setter setter = new setter (listbloxime background background, binding); Style style = new genre (typef (listbloxime)); Style.Setters.Add (setter); ListBox.ItemContainerStyle = Style;
If I try to run it then after starting my Silverlight control I get Logic Execution
.
What am I doing wrong? How can I bind a property for item property to ItemContainerStyle
?
API's seriallight (3 too) does not support binding on style setters. To change the background color on each item loading, you have to do some custom logic - possibly getting your parents in the visual tree, which container, and have to set it there.
Comments
Post a Comment