wpf - My databinding with value converter does not work -
I have a simple item-square that looks like this:
public Class item: dependency object {public at not {received} return (gate) gateway (no property); } Set {set value (no property, value); }} Public string name {get {return (string) GetValue (NameProperty); } Set {set value (nameproperty, value); }} Dependent Property No Property = Dependency Property for public static reading. Registration ("no", typef, typef (item)); Public static read-only dependency Property Name: Representative = Dependency Property Registration ("name", typef (string), typef (item)); }
and a ValueConverter, which looks like this:
[value conversion (typef (item), typef (string)) internal class ItemToStringConverter: IValueConverter {convert public object (type object value, type type, object parameter, culture info culture) {if (value == null) {return null; } Var items = ((item) value); Var sb = new stringbilder (); Sb.AppendFormat ("item # {0}", item number); If (string.IsNullOrEmpty (item.Name) == incorrect) {sb.AppendFormat ("- [{0}]", item.Name); } Return sb.ToString (); } Public Object Convertback (Object Value, Type Type, Object Parameter, Culture Information Culture) {New Non Imulated Expansion (); }}
On my WPF window, I declare a dependency property (called item) which keeps a list of item objects (list & item icon) and combo Creates a box that binds this dependency property. XML-code:
& lt; Combo box item source = "{binding element name = main window, path = item}" & gt; & Lt; ComboBox.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; Text block text = "{binding converter = {static resource item touting controller}}" /> & Lt; / DataTemplate & gt; & Lt; /ComboBox.ItemTemplate> & Lt; / ComboBox & gt;
If I execute the code once, the database works fine, even if it executes again, the value converge fails:
< Pre> var item1 = new item {name = "item A", not = 1}; Var item2 = new item {name = "item b", not = 2}; Var item 3 = new item {name = "item c", not = 3}; Item = new list & lt; Items & gt; {Item 1, item 2, item 3};
The problem is that itemostorcentant Convert method has now passed the string object as the first parameter instead of an object object?
What am I doing wrong?
Regards, Kenneth
The type of simple passage must be examined Change the change method in your ValueConverter as follows:
Convert public objects (type object type, type type, object parameter, culture environment) {var item = value as item; If (item == zero) {return tap; } Var sb = new stringbilder (); Sb.AppendFormat ("item # {0}", item number); If (string.IsNullOrEmpty (item.Name) == incorrect) {sb.AppendFormat ("- [{0}]", item.Name); } Return sb.ToString (); }
Comments
Post a Comment