使用嵌入式表达式时无法识别控件 [英] Control is not recognized when using embedded expression

查看:64
本文介绍了使用嵌入式表达式时无法识别控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了简单的模板查看器:

I have created simple template viewer:

Imports <xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

私有 Sub ShowTemplate ()
使用ms
= MemoryStream ()
Dim b = < 按钮 />
XamlW riter
保存 DirectCast XamlReader Parse b ToString ()), Control )。 模板 ms
ms
位置 < span class ="pun"> = 0L
txt
文字 = XElement 加载 毫秒 )。 ToString ()
结束 使用
结束 Sub

Private Sub ShowTemplate() Using ms = New MemoryStream() Dim b = <Button/> XamlWriter.Save(DirectCast(XamlReader.Parse(b.ToString()), Control).Template, ms) ms.Position = 0L txt.Text = XElement.Load(ms).ToString() End Using End Sub

这个工作正常,直到我使用嵌入式表达式。想法是用户通过在文本框中键入控件来获取控件的模板。此条目从用户的条目创建XElement,并显示模板。

This works fine until I use embedded expression. The idea is that the user gets control's template by typing the control in text box. This entry creates XElement from user's entry, and template is shown.

Imports <xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

私有 Sub ShowTemplate ()
使用ms
= MemoryStream ()
Dim sButton = "按钮"
昏暗 b = <<%= sButton %> />
XamlWriter
保存 DirectCast XamlReader 解析 b ToString ()), 控制 )。 模板 ms
ms
位置 = 0L
txt
文字 = XElement 加载 ms )。 ToString ()
结束 使用
结束 Sub

Private Sub ShowTemplate() Using ms = New MemoryStream() Dim sButton = "Button" Dim b = <<%= sButton %>/> XamlWriter.Save(DirectCast(XamlReader.Parse(b.ToString()), Control).Template, ms) ms.Position = 0L txt.Text = XElement.Load(ms).ToString() End Using End Sub

此代码抛出异常:  '无法创建未知类型'Button'

This code throws exception: 'Cannot create unknown type 'Button'.

没有不知道的知识。

推荐答案

这看起来更像是VB相关的问题。据我所知,问题与xml缺少的命名空间有关。如果您查看第一个示例生成的xml,您会看到:

This looks more like a VB related question. As far as I can tell the problem is related to an xml missing namespace. If you look at the xml generated by the first example you'll see this:

< Button xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation " />

<Button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />

,而第二个例子生成:

< Button />

<Button />

显然在第二种情况下,缺少xml命名空间,但遗憾的是我不熟悉VB及其XML文字来提出解决方案。

Clearly in the second case the xml namespace is missing but unfortunately I'm not familiar with VB and its XML literals to suggest a solution.


这篇关于使用嵌入式表达式时无法识别控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆