TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Amit K
NA
3
5.8k
Loading user controls dynamically in Mainwindow
Jul 28 2016 4:36 PM
'm working on a C# WPF application.I've a list of user controls UC1,UC2 and UC3.And all internally refer to another common user control called UCB. And my App.xaml refers to MainWindow.xml
UCB has a dropdown list with names of different account types.
I need to programmatically show the user control in MainWindow depending upon the account type selected in the Base user control UCB.How do I achieve this please?
My thoughts so far: May be I can instantiate all my user controls in MainWindow.xaml.cs file like this:
UserControl uc1 = (UserControl)assembly.CreateInstance(string.Format("{0}.MyUC1", type.Namespace));
UserControl uc2 = (UserControl)assembly.CreateInstance(string.Format("{0}.MyUC2", type.Namespace));
userControls.Add("1", uc1);
userControls.Add("2", uc2);
and then use the MainWindow.xaml's content property to set the desired user control based on the dropdown value.
this.Content = userControls["1"];
But how do I access this content property inside ComboBox_SelectionChanged event in UCB control??
Please advise.
Thanks.
Reply
Answers (
1
)
DataGrid Toggle Button Click
How to enable Radio Button