c# - Persist Dynamically Added Controls w/ DataTriggers WPF -


i working on wpf project uses caliburn.micro , have hit snag hoping with. have form allows user add new fields separate form intention these new fields persist. able create these controls dynamically following code:

        grid tmpoutergrid = new grid();         rowdefinition rowdefinition1 = new rowdefinition();         rowdefinition rowdefinition2 = new rowdefinition();         rowdefinition1.height = new gridlength(45, gridunittype.star);         rowdefinition2.height = new gridlength(55, gridunittype.star);         tmpoutergrid.rowdefinitions.add(rowdefinition1);         tmpoutergrid.rowdefinitions.add(rowdefinition2);         tmpoutergrid.margin = new thickness(0,0,0,10);          grid tmpinnergrid = new grid();         grid.setrow(tmpinnergrid, 0);         tmpinnergrid.margin = new thickness(10,0,0,5);         tmpinnergrid.opacity = 0;          datatrigger d = new datatrigger();         binding b = new binding("displayfieldname");         b.source = _fieldnames[primarynamebase + "fieldtextbox"];         d.binding = b;         d.value = true;          storyboard sbenter = new storyboard();         doubleanimation opanimshow = new doubleanimation(1,new duration(new timespan(0,0,0,1)));         storyboard.settargetproperty(sbenter, new propertypath(uielement.opacityproperty));         sbenter.children.add(opanimshow);          storyboard sbexit = new storyboard();         doubleanimation opanimhide = new doubleanimation(0, new duration(new timespan(0, 0, 0, 1)));         storyboard.settargetproperty(sbexit, new propertypath(uielement.opacityproperty));         sbexit.children.add(opanimhide);          beginstoryboard bsenter = new beginstoryboard { storyboard = sbenter, name = "beginstoryboardenter" };         beginstoryboard bsexit = new beginstoryboard { storyboard = sbexit, name = "beginstoryboardexit" };          d.enteractions.add(bsenter);         d.exitactions.add(bsexit);          style st = new style(typeof(grid));         st.triggers.add(d);         tmpinnergrid.style = st;          textblock tb = new textblock();         tb.name = primarynamebase + "fieldheadertext";         tb.foreground = new solidcolorbrush(color.fromargb(136,255,255,255));         tb.fontsize = 14;         tb.style = (style) app.current.resources["nexalighttextblock"];         tb.horizontalalignment = horizontalalignment.center;         tb.text = fieldtextbox.displaytext;          border underline = new border();         underline.borderthickness = new thickness(0, 0, 0, 1);         underline.borderbrush = new solidcolorbrush(color.fromargb(136,49,250,250));         underline.verticalalignment = verticalalignment.bottom;         underline.horizontalalignment = horizontalalignment.center;          binding binding = new binding         {             source = tb,             path = new propertypath("actualwidth"),         };         underline.setbinding(frameworkelement.widthproperty, binding);          tmpinnergrid.children.add(tb);         tmpinnergrid.children.add(underline);          lowbordertextbox lbtb = new lowbordertextbox();         lbtb.name = primarynamebase + "fieldtextbox";         grid.setrow(lbtb, 1);         lbtb.width = 140;         lbtb.margin = new thickness(10,0,0,0);         lbtb.fontcolor = new solidcolorbrush(colors.white);         lbtb.displayfontsize = 22;         lbtb.style = (style) app.current.resources["nexalightcustomtextbox"];         lbtb.displaytext = fieldtextbox.displaytext;         lbtb.lostfocus += fieldlostfocus;          tmpoutergrid.children.add(tmpinnergrid);         tmpoutergrid.children.add(lbtb);          wrappanel.children.add(tmpoutergrid); 

i these new controls persisted through application shutdowns. approach thinking of taking serializing object xaml , storing in file, , reading file , deserializing obtain control object again, added surrounding wrappanel. fine , dandy except 1 detail. controls created have style datatrigger bound property of notefield object, there being 1 notefield object each of these types of control. planning on serializing notefield objects well, pull them , hope binding still intact, implement propertychangedbase interface of caliburn.micro framework, , notifyofpropertychange() method not marked serializable. here notefield class:

[serializable] class notefield : propertychangedbase {     private string _controlname;      private bool _displayfieldname;      public bool displayfieldname     {         { return _displayfieldname; }         set         {             _displayfieldname = value;             notifyofpropertychange(() => displayfieldname);         }     }      private string _fieldname;      public string fieldname     {         { return _fieldname; }         set         {             _fieldname = value;             notifyofpropertychange(() => fieldname);         }     }      public notefield(string controlname, string displaytext)     {         displayfieldname = false;         _controlname = controlname;         fieldname = displaytext;     }      public string getcontrolname()     {         return _controlname;     }      public void setcontrolname(string name)     {         _controlname = name;     } } 

i not attached using class, way think of having dynamically generated properties bind xaml. so, guess question is: there way can dynamically create controls have bindings in them can persist through application shutdowns? on right track, or should else together? appreciated. thank time.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -