在 wp7 中自定义控件/编写控件模板

发布于 2025-01-05 02:15:38 字数 1278 浏览 3 评论 0原文

我一直在尝试在wp7中自定义一个web浏览器控件。我需要做的就是添加一个边框属性(我认为它已经在网络浏览器中可用,但当我将其作为控件时我必须将其强制执行)并希望添加一些额外的事件处理程序并将其作为控件以便以后可以在不同的项目中使用。

我尝试阅读 msdn 中的材料来编写控制模板,这一切都围绕着编写一些 xaml 代码并将其附加到代码隐藏以使其工作。我不明白的是我如何学习xaml?或者换句话说,msdn 在 xaml 中讨论的所有标签的参考在哪里?它似乎很大,我不知道该怎么做。 msdn中的教程直接泄露了xaml代码,我完全困惑了..

所以现在我想做的就是这个,

  1. 在 Expression Blend(Windows Phone 控件库)中创建一个控件,该控件将创建一个继承的类 (MyCustomControl) 来自 CustomControl 基类。

  2. 现在,在 xaml 中,我添加一个网络浏览器控件并添加四个事件处理程序(mouseup、down 等)。

  3. 我在blend中构建了这个控件,并在VS2010中添加了相应的dll。

  4. 现在,当我尝试将此控件添加到我的 wp7 手机应用程序时,它会显示“无法创建 MyCustomControl 的实例”。

这些是我在创建实例时引用的进一步链接, Windowsphone - 创建自定义控件 Windowsphone - 控件模板。 用户控件与自定义控件 通过创建 ControlTemplate 来创建新控件

任何进一步的帮助都会很棒。

I have been trying to customize a webbrowser control in wp7. All I need to do is to add a border property(I think it is already available in webbrowser but I have to make it mandatory when I make it as a control) and want to add a few extra event handlers and make it as a control so that it can be used later in different projects.

I tried reading through materials in msdn for writing control template and it all revolves around writing a few xaml code and attaching it with codebehind to make it work. What I don't understand is how do I learn xaml? or in other words where is the reference for all the tags that msdn talks about in xaml? Itseems to be huge and I am not sure how to go about it. The tutorial in msdn straight away divulges into xaml code and I am totally confused..

So now all I am trying to do is this,

  1. create a control in Expression Blend (Windows Phone Control Library) that would create a class (MyCustomControl) that inherits
    from CustomControl base class.

  2. Now in xaml I am adding a webbrowser control and adding four event handlers (mouseup,down etc.,).

  3. I build this control in blend and add the corresponding dll in VS2010.

  4. And now once I try to add this control to my wp7 phone application it says "Cannot create an instance of MyCustomControl"..

These were further links that I referenced in creating one,
Windowsphone - Creating a custom control
Windowsphone - Control Template.
UserControl vs Custom Control
Creating a new control by creating ControlTemplate

Any further help would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑕疵 2025-01-12 02:15:38

没有可以添加到 XAML 中的“元素”的明确列表。原因是 XAML 解析器可以根据您提供的 XML 创建任何 UIElement 类。因此,您可用的元素取决于项目中存在的程序集。有关详细信息,请阅读 MSDN XAML 概述

有关现有控件的列表默认情况下,请查看 System.Windows.Controls 命名空间(我认为此链接不适用于您的 Silverlight 版本,最好使用对象浏览器查看程序集在你的项目中)。

对于您的问题,您想要向 WebBrowser 控件添加边框。我建议创建一个 UserControl 按照本教程

There is no definitive list of 'elements' you can add to your XAML. The reason for this is that the XAML parser can create any class which is a UIElement based on the XML you provide. So the elements available to you depend on the assemblies present in your project. Read teh MSDN XAML Overview for details

For a list of controls that are present by default, take a look at the System.Windows.Controls namespace (I think this link is not for your version of Silverlight, it might be best to use the Object Browser to look at the assemblies in your project).

For your problem, where you want to add a border to a WebBrowser control. I would recommend creating a UserControl as per this tutorial.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文