简体   繁体   English

WebBrowser控件包装在自定义类中

[英]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? 一般来说,我对C#和.NET还是很陌生,所以这似乎是一个愚蠢的问题? 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....." 我需要一些有关语句“究竟是什么”的帮助,“首先,我将WebBrowser控件包装在一个自定义类中以添加功能,在该类中,我声明此常量.....”

At the moment I have the WPF Webbrowser Control manually added as in the XAML below 目前,我已手动添加了WPF Webbrowser控件,如下面的XAML所示

<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? 我假设我只需要创建一个新类(例如WebBrowserCustom.cs)并添加这些事件? But I'm struggling to understand how I then add it to a WPF window? 但是我很难理解如何将其添加到WPF窗口中?

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....." 我需要一些有关语句“究竟是什么”的帮助,“首先,我将WebBrowser控件包装在一个自定义类中以添加功能,在该类中,我声明此常量.....”

It's just a user control. 这只是一个用户控件。 Which, in your code, will inherit from UserControl . 在您的代码中,它们将从UserControl继承。 There are countless examples out there. 那里有无数的例子。 You can get started on MSDN though, which is a great resource. 不过,您可以开始使用MSDN ,这是一个很好的资源。 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 . 创建控件(实质上是包装WebBrowser控件)后,就可以从UserControl公开事件和属性。 I suggest you get started on the basics first though so you can understand what is going on. 我建议您先从基础开始,这样您可以了解发生了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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