c# - Having some trouble creating a UserControl with a parameter -


i use tabcontrol in 1 of classes. however, don't want bloat class , put code in it, xaml tabitems.

after googling i've come usercontrol. created usercontrol every tabitem, c# code of tabitem in usercontrol.

the problem here, need transfer data parent window (the 1 containing tabcontrol) usercontrols, correctly display data needed tab.

i created usercontrol in xaml , code this:

<tabitem name="usertab" header="gebruikers" horizontalalignment="stretch">         <local:usertabcontrol x:name="usertabpanel"/> </tabitem> 

this constructor code usercontrol:

public usertabcontrol() {         setusersview(); // need data         setuserdata((user)usersview.selecteditem);         initializecomponent();  } 

this class variable in usercontrol needs variable parent window: private static parser m_config;

when run this, compile error saying :

"object reference not set instance of object."

pointing xaml line create usercontrol.

so, conclusion here yet unable pass variable usercontrol , have suggestions or hints or guidance on how in case. going wrong here in achieving required functionality ?

im not sure best way so, me worked well.

for start create customusercontrol class inherit usercontrol constractor parent form attribute this:

public partial class customusercontrol : usercontrol {    mainform parentform;    public customusercontrol(mainform mainform)    {       parentform = mainform;    }    ...     ...    private void dosomthing()    {       parentform.mainformmember = 1;    } } 

and in mainform:

public partial class mainform : form {    private int mainformmember{ get; set; }    private customusercontrol customusercontrol;     public mainform()    {         initializecomponent();          // create , add customusercontrol manually , not toolbox         customusercontrol = new customusercontrol(this);         this.controls.add(customusercontrol);    }     ...    ... } 

in way can access form components usercontrol


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -