Created
May 13, 2010 17:22
-
-
Save PilotBob/400100 to your computer and use it in GitHub Desktop.
Create Silverlight tabItems and add user controls to it dynamically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void PopulateDashBoard(object sender, EventArgs e) | |
{ | |
LoadOperation<UserSnapin> op = sender as LoadOperation<UserSnapin>; | |
_entities = op.Entities; | |
string currentPage = String.Empty; | |
TabItem tabItem; | |
Canvas tabCanvas = null; | |
foreach (var UserSnapin in _entities) | |
{ | |
// Add a page if needed | |
if (currentPage != UserSnapin.Page) | |
{ | |
currentPage = UserSnapin.Page; | |
tabItem = new TabItem(); | |
tabItem.Header = UserSnapin.Page; | |
tabItem.Content = new Canvas(); | |
tabCanvas = tabItem.Content as Canvas; | |
Pages.Items.Add(tabItem); | |
} | |
Type snapInType = Assembly.GetExecutingAssembly() | |
.GetType(UserSnapin.Snapin.Source); | |
UIElement uc = (UIElement)Activator.CreateInstance(snapInType); | |
Canvas.SetLeft(uc, UserSnapin.PositionLeft); | |
Canvas.SetTop(uc, UserSnapin.PositionTop); | |
uc.MouseLeftButtonDown += new MouseButtonEventHandler(Handle_MouseDown); | |
uc.MouseMove += new MouseEventHandler(Handle_MouseMove); | |
uc.MouseLeftButtonUp += new MouseButtonEventHandler(Handle_MouseUp); | |
// Add the canvas to the tabCanvas of the page | |
tabCanvas.Children.Add(uc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment