简体   繁体   中英

WebBrowser control wrapped in a custom class

I'm quite new to C# and .NET in general so this may seem like a silly question? I'm trying to follow this advice here

I need some help on what exactly is meant by the statement "First of all I have my WebBrowser control wrapped in a custom class to add functionalities, in that class I declare this constant....."

At the moment I have the WPF Webbrowser Control manually added as in the XAML below

<Window x:Class="ProjectX.WebbrowserWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="WebbrowserWindow" Height="378" Width="632">
    <Grid>
        <WebBrowser HorizontalAlignment="Stretch" Margin="0,32,0,0" Name="webBrowser1" VerticalAlignment="Stretch" Navigated="webBrowser1_Navigated" />
        <Button Content="Go!" Height="22" HorizontalAlignment="Left" Margin="507,3,0,0" Name="button1" VerticalAlignment="Top" Width="78" Click="button1_Click" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="4,2,0,0" Name="textBox1" VerticalAlignment="Top" Width="497" />
    </Grid>
</Window>

I'm assuming I just need to create a new class (say WebBrowserCustom.cs) and add those events? But I'm struggling to understand how I then add it to a WPF window?

Thank you

I need some help on what exactly is meant by the statement "First of all I have my WebBrowser control wrapped in a custom class to add functionalities, in that class I declare this constant....."

It's just a user control. Which, in your code, will inherit from UserControl . There are countless examples out there. You can get started on MSDN though, which is a great resource. I even found a video here that would help you get started. Once you create your control, which is essentially wrapping a WebBrowser control, you can expose events and properties from your UserControl . I suggest you get started on the basics first though so you can understand what is going on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM