Control is not recognized when using embedded expression

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have created simple template viewer:
<pre class="prettyprint lang-vb prettyprinted" style=" <span class="kwd Imports<span class="pln <span class="pun <<span class="pln xmlns<span class="pun =<span class="str "http://schemas.microsoft.com/winfx/2006/xaml/presentation"<span class="pun > <span class="kwd Private<span class="pln <span class="kwd Sub<span class="pln ShowTemplate<span class="pun ()<span class="pln
Using ms <span class="pun =<span class="pln <span class="kwd New<span class="pln MemoryStream<span class="pun ()<span class="pln
<span class="kwd Dim<span class="pln b <span class="pun =<span class="pln <span class="pun <<span class="pln Button<span class="pun /><span class="pln
XamlWriter<span class="pun .<span class="pln Save<span class="pun (<span class="kwd DirectCast<span class="pun (<span class="pln XamlReader<span class="pun .<span class="pln Parse<span class="pun (<span class="pln b<span class="pun .<span class="pln ToString<span class="pun ()),<span class="pln Control<span class="pun ).<span class="pln Template<span class="pun ,<span class="pln ms<span class="pun )<span class="pln
ms<span class="pun .<span class="pln Position <span class="pun =<span class="pln <span class="lit 0L<span class="pln
txt<span class="pun .<span class="pln Text <span class="pun =<span class="pln XElement<span class="pun .<span class="pln Load<span class="pun (<span class="pln ms<span class="pun ).<span class="pln ToString<span class="pun ()<span class="pln
<span class="kwd End<span class="pln Using
<span class="kwd End<span class="pln <span class="kwd Sub [/code]

This works fine until I use embedded expression. The idea is that the user gets controls template by typing the control in text box. This entry creates XElement from users entry, and template is shown.
<pre class="prettyprint lang-vb prettyprinted" style=" <span class="kwd Imports<span class="pln <span class="pun <<span class="pln xmlns<span class="pun =<span class="str "http://schemas.microsoft.com/winfx/2006/xaml/presentation"<span class="pun > <span class="kwd Private<span class="pln <span class="kwd Sub<span class="pln ShowTemplate<span class="pun ()<span class="pln
Using ms <span class="pun =<span class="pln <span class="kwd New<span class="pln MemoryStream<span class="pun ()<span class="pln
<span class="kwd Dim<span class="pln sButton <span class="pun =<span class="pln <span class="str "Button"<span class="pln
<span class="kwd Dim<span class="pln b <span class="pun =<span class="pln <span class="pun <<%=<span class="pln sButton <span class="pun %>/><span class="pln
XamlWriter<span class="pun .<span class="pln Save<span class="pun (<span class="kwd DirectCast<span class="pun (<span class="pln XamlReader<span class="pun .<span class="pln Parse<span class="pun (<span class="pln b<span class="pun .<span class="pln ToString<span class="pun ()),<span class="pln Control<span class="pun ).<span class="pln Template<span class="pun ,<span class="pln ms<span class="pun )<span class="pln
ms<span class="pun .<span class="pln Position <span class="pun =<span class="pln <span class="lit 0L<span class="pln
txt<span class="pun .<span class="pln Text <span class="pun =<span class="pln XElement<span class="pun .<span class="pln Load<span class="pun (<span class="pln ms<span class="pun ).<span class="pln ToString<span class="pun ()<span class="pln
<span class="kwd End<span class="pln Using
<span class="kwd End<span class="pln <span class="kwd Sub [/code]
This code throws exception: Cannot create unknown type Button .
The required namespace is imported, so the code should work, but it doesnt. Please, help me to find a solution!<hr class="sig There is no knowledge that is not power.

View the full article
 
Back
Top