c# - WPF Binding to dictionary with classes -


i new wpf programming , not professional in c# coding.

so have following problem: have lot of different comboboxes , textboxes. want bind them variable in background, because want fill comboboxes data database.

so created following in file
liste.xaml.cs:

private dictionary<string, filter> _ctrlfilter;  public dictionary<string, filter> ctrlfilter {     { return _ctrlfilter; }     set { _ctrlfilter = value; } } 

when load liste.xaml initializes ctrlfilter dictionary following code:

ctrlfilter = new dictionary<string, filter> {   //combobox   {"hersteller", new filter("hersteller", typeof(combobox)) },   {"fahrzeugart", new filter("fahrzeugart", typeof(combobox), false) },    //textbox   {"baujahr", new filter("baujahr", typeof(textbox), true, typeof(short)) },   {"anschaffungswert", new filter("anschaffungswert", typeof(textbox), true, typeof(decimal)) },   {"finanz_restwert", new filter("restwert", typeof(textbox), true, typeof(decimal)) },    //others   {"zugelassen", new filter("zugelassen", typeof(datepicker), true, typeof(datetime)) },   {"vstabzug", new filter("vorsteuerabzug", typeof(checkbox), true, typeof(bool)) }, }; 

so filter class (which in liste.xaml.cs) looks this:

public class filter {     public string filtername;     public type controltype;     public type fromtotype;     public bool load;     public observablecollection<object> items;     public object selectedfilter;     public object from;     public object to;      public filter( string name, type type, bool load = true, type fttype = null)     {         reset();         filtername = name;         controltype = type;         load = load;         fromtotype = fttype;     }      public void reset()     {         = null;         = null;         selectedfilter = null;         items = new observablecollection<object>();     } } 

now dynamically load other xaml-files liste.xaml file. example fahrzeug_allgemein.xaml

there have comboboxes, looks this:

            <stackpanel>                 <label content="hersteller:" target="{binding elementname=cmb_hersteller, mode=oneway}"/>                 <combobox x:name="cmb_hersteller" fahrzeuge:filterextension.filtername="hersteller"  width="120" itemssource="{binding ctrlfilter[hersteller].items}" selectedindex="0" selectionchanged="cmb_hersteller_selectionchanged"/>             </stackpanel> 

you see tried items property filter class, doesn't work. in visual studio 2015 output says:

system.windows.data error: 40 : bindingexpression path error: 'items' property not found on 'object' ''filter' (hashcode=44888241)'. bindingexpression:path=ctrlfilter[hersteller].items; dataitem='liste' (name=''); target element 'combobox' (name='cmb_hersteller'); target property 'itemssource' (type 'ienumerable') 

i read inotifypropertychanged not know how use in case.

it cool, if me. thank you.

i haven't thought answer simple. had add { get; set; } items property.

so code looks now:

public class filter {     public string filtername;     public type controltype;     public type fromtotype;     public bool load;     public observablecollection<comboboxitem> items { get; set; }     ... 

i think means, items property able bind addition.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -