I have a working application written in C #, and now I want to expand this application to allow the user to switch between viewing the application and viewing the built-in web browser (inside the same application window).
I also have a separate working web browser, which was also written in C #.
I just added functionality to the original application to enable tabbed displays where the original application will appear on the first tab and the built-in web browser on the second tab.
Tabbed mappings for the application were created using XAML markup in Visual Studio. Now I want to add a web browser instance that was also written in C # to the second tab that I created in the XAML markup.
It will be something like:
<TabControl> <TabItem Header="Browser"> <StackPanel> </StackPanel> </TabItem> </TabControl>
But I have no idea how I call / instantiate the browser from the XAML markup ...
The browser was created using C #:
namespace Agent { public partial class Browser : Form { public Browser() { ... } } }
Can someone explain to me how to create an instance of the Browser inside the XAML markup?
Edit
Ok, so I edited my XAML markup as recommended in the answer that was suggested - now I have:
<Window ... xmlns:Agent="clr-namespace:Agent" ...> <Grid> ... <TabControl> <TabItem Header="R"> <StackPanel> ... </StackPanel> </TabItem> <TabItem Header="Browser"> <Agent:Browser x:Name="Browser" /> </TabItem> </TabControl> </Grid> </Window>
I also updated my Browser.cs class, so now it extends UserControl , not Form :
public partial class Browser : UserControl{
However, I get a compilation error in the line:
<Agent:Browser x:Name="Browser" />
which reads:
The name "Browser" does not exist in the namespace "clr-namespace: Agent".
But itβs clear that the Browser exists in Agent , as shown in the code that I included here ... In fact, when I entered the line <Agent:Browser x:Name="Browser /> , when I typed : Browser was one of the options, appearing in the autocomplete menu ...
What am I doing wrong here? Why doesn't the compiler think that the Browser exists inside the Agent ?