Walkthrough: Adding a DLL Reference to the Start Page
This walkthrough shows how to add a DLL reference to a custom Start Page. The example adds a user control to the solution, builds the user control, and then references the built assembly from the Start Page .xaml file. A new tab hosts the user control, which functions as a basic Web browser.
You can use the same process to add any assembly that can be called from a .xaml file.
First, add a Windows Presentation Foundation (WPF) user control to the Start Page solution.
To add a WPF user control to the Start Page solution
Create a Start Page by using the Start Page project template. For more information, see Start Pages.
In Solution Explorer, right-click the solution, click Add, and then click New Project.
In the left pane of the New Project dialog box, expand either the Visual Basic or Visual C# node, and click Windows. In the middle pane, select WPF User Control Library.
Name the control WebUserControl and then click OK.
To implement a WPF user control, build the user interface (UI) in XAML and then write the code-behind events in C# or another .NET language.
To write the XAML for the user control
In Solution Explorer, open the XAML file for the User Control.
In the Grid element, add the following row definitions to the User control.
In the main Grid element, add the following new Grid element, which contains a text box for typing Web addresses and a button for setting the new address.
Add the following frame to the top-level Grid element just after the Grid element that contains the button and textbox.
The following example shows the completed XAML for the user control.
<UserControl x:Class="WebUserControl.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid Grid.Row="0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <TextBox x:Name="UserSource" Grid.Column="0" /> <Button Grid.Column="1" x:Name="SetButton" Content="Set Address" Click="SetButton_Click" /> </Grid> <Frame Grid.Row="1" x:Name="WebFrame" Source="http://www.bing.com" Navigated="WebFrame_Navigated" /> </Grid> </UserControl>
To write the code-behind events for the user control
In the XAML designer, double-click the Set Address button you added to the control.
The UserControl1.cs file opens in the code editor.
Fill in the SetButton_Click Event Handler as follows.
This code sets the Web address that is typed in the text box as the target for the Web browser. If the address is not valid, the code throws an error.
Build the solution.
To make this control available to the Start Page project, in the Start Page project file, add a reference to the new control library. Then you can add the control to the Start Page XAML markup.
To add the user control to the project
In Solution Explorer, in the Start Page project, right-click References and then click Add Reference.
On the Projects tab, select WebUserControl and then click OK.
On the Build menu, click Build Solution.
Building the solution makes the user control available to IntelliSense for other files in the solution.
To add the control to the Start Page XAML markup, add a namespace reference to the assembly, then put the control on the page.
To add the control to the markup
In Solution Explorer, open the Start Page .xaml file.
In the XAML pane, add the following namespace declaration to the top-level Grid element.
In the XAML pane, scroll to the section that has the comment <!—Center Content-->.
Now you can test the control.
To test the custom Start Page
The experimental instance of Visual Studio opens, with the custom Start Page installed but not selected.
In the experimental instance of Visual Studio, on the Tools menu, click Options.
In the Options dialog box, under Environment, select Startup. Then, on the Customize Start Page list, select your .xaml file, and click OK.
If the Start Page is not displayed, on the View menu, click Start Page.
Click the Web tab.
Type a URL into the search box and then click the Set Address button.
The Web page loads.
You can share custom Start Pages with other users by uploading the .vsix file from the /Bin/Debug/ folder of the project to the Visual Studio Gallery Web site, or to another Web site or intranet share.