Skip to content

Instantly share code, notes, and snippets.

@PilotBob
Created May 13, 2010 17:22
Show Gist options
  • Save PilotBob/400100 to your computer and use it in GitHub Desktop.
Save PilotBob/400100 to your computer and use it in GitHub Desktop.
Create Silverlight tabItems and add user controls to it dynamically.
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