Skip to main content

Microsoft Silverlight

Answered Question typecast string into silverlight usercontrol type.RSS Feed

(0)

mehtapratik
mehtapratik

Member

Member

269 points

302 Posts

typecast string into silverlight usercontrol type.

 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

Pratik Mehta
Espirit Softwares Pvt. Ltd.
India.

fullsailrick
fullsail...

Contributor

Contributor

3699 points

829 Posts

Re: typecast string into silverlight usercontrol type.

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.dharwala
murtaza....

Participant

Participant

1659 points

378 Posts

Re: typecast string into silverlight usercontrol type.

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

 

Murtaza Dharwala
Diaspark Inc.
www.diaspark.com
email:murtaza.dharwala@diaspark.com


Please remember to click “Mark as Answer” on the post that helps you

mehtapratik
mehtapratik

Member

Member

269 points

302 Posts

Answered Question

Re: Re: typecast string into silverlight usercontrol type.

 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);

Pratik Mehta
Espirit Softwares Pvt. Ltd.
India.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities