Answered by:
Load a usercontrol dynamic

Question
-
Hi
I have in my application a accordion control with hyperlinkbuttons. When a user press for example the hyperlink
"Products", then i want to load the user control "Products.xaml". How i can do that ???Sunday, November 21, 2010 9:30 AM
Answers
-
Hi,
Navigation Framework is much more easier to manage.
But it depends on what kind of application you are developing.
Regards
Sunday, November 21, 2010 10:35 AM
All replies
-
Hi,
Do you want to instantiate a UserControl based on a string.
Like you have Products So i will instantiate "Products.xaml"
For this you can use Activator.CreateInstance("Products")Regards
Sunday, November 21, 2010 9:52 AM -
depending on how you are trying to do things if you just have a content presenter besides your accordion control with a name then you can just in the click event for a give button set it to a new instance of the control you would like
OnProductClick(object sender,RoutedEventArgs e) { _myContent = new Products(); }
Sunday, November 21, 2010 9:55 AM -
Where do you want to put this UserControl? You need to creat this UserControl then add it to the VisualTree.
Say you have a Grid called "container" as a placeholder for this control in your page:
Products p = new Products();
this.container.Children.Add(p);
Sunday, November 21, 2010 10:02 AM -
thanks, that works but i found something else.
What do you think about the Navigation Framework and the uri mapper. Which solution is better ??
i mean this:
<UserControl x:Class="SilverlightApplication4.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" xmlns:uriMapper="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> <Grid x:Name="LayoutRoot" Style="{StaticResource LayoutRootGridStyle}"> <Border x:Name="ContentBorder" Style="{StaticResource ContentBorderStyle}"> <navigation:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}" Source="/Home" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed"> <navigation:Frame.UriMapper> <uriMapper:UriMapper> <uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/> <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/> </uriMapper:UriMapper> </navigation:Frame.UriMapper> </navigation:Frame> </Border> <Grid x:Name="NavigationGrid" Style="{StaticResource NavigationGridStyle}"> <Border x:Name="BrandingBorder" Style="{StaticResource BrandingBorderStyle}"> <StackPanel x:Name="BrandingStackPanel" Style="{StaticResource BrandingStackPanelStyle}"> <ContentControl Style="{StaticResource LogoIcon}"/> <TextBlock x:Name="ApplicationNameTextBlock" Style="{StaticResource ApplicationNameStyle}" Text="Anwendungsname"/> </StackPanel> </Border> <Border x:Name="LinksBorder" Style="{StaticResource LinksBorderStyle}"> <StackPanel x:Name="LinksStackPanel" Style="{StaticResource LinksStackPanelStyle}"> <HyperlinkButton x:Name="Link1" Style="{StaticResource LinkStyle}" NavigateUri="/Home" TargetName="ContentFrame" Content="Startseite"/> <Rectangle x:Name="Divider1" Style="{StaticResource DividerStyle}"/> <HyperlinkButton x:Name="Link2" Style="{StaticResource LinkStyle}" NavigateUri="/About" TargetName="ContentFrame" Content="Info"/> </StackPanel> </Border> </Grid> </Grid> </UserControl>
Sunday, November 21, 2010 10:28 AM -
Hi,
Navigation Framework is much more easier to manage.
But it depends on what kind of application you are developing.
Regards
Sunday, November 21, 2010 10:35 AM -
I want to develop an online shop. but the online shop is in asp.net and the management tool i want to develop in silverlight.
i thinks thats possible but im not sure. what would you recommend for me ?Sunday, November 21, 2010 10:37 AM -
Navigation framework sounds like it would probably work well for your needs.
Monday, November 29, 2010 10:46 AM