Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit typecast string into silverlight usercontrol type.
3 replies. Latest Post by mehtapratik on March 7, 2009.
(0)
mehtapratik
Member
269 points
302 Posts
03-07-2009 2:01 AM |
Hi everyone, i am facing one issue.
I am generating dynamic menus from the database and there is one field call pagetype in the database of the type string.
When the menu item click, i have to redirect it to specific page, but i unable to do it because we cant typecast string into usercontrol type.
Any suggestions?
Thanks
fullsail...
Contributor
3699 points
829 Posts
03-07-2009 2:21 AM |
Hi! Make a new Object that links (by shared container) the two types: Bind the Presentation string to the field -- this will also be stored along with a type inside of your container. Then, when you go to create that type, loop through a List of your MenuTypes, find the correct Presentation string and it will also tell you the type. (Because you have that object that is stored with it.) A Dictionary would also be good for this.
murtaza....
Participant
1659 points
378 Posts
03-07-2009 2:25 AM |
you can do one thing
you can put the ClassName of your Usercontrols in your pagetype column
and when your click on menu get the pagetype it will give u the classname as string
then you can use
the Assembly.CreateInstance() method to initiate your user control
03-07-2009 3:59 AM |
Hi Murtaza,
You may correct, but i found another way.
Type ucType = Type.GetType(this.GetType().Namespace +"." +objSubmenu.PageURL); UserControl objUc =(UserControl) Activator.CreateInstance(ucType);