Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing static objects in XAML that were created in code in Silverlight
    primarykey
    data
    text
    <p>I couldn't get this to work in Silverlight, so I created two test projects. One simple WPF project and one simple Silverlight project that both do only one thing: set a public static readonly variable in code, and use it in a completely bare bones XAML. In WPF, works without a hitch. In Silverlight, I get the following compiler warning and runtime error:</p> <p><strong>Warning 2 The tag 'Static' does not exist in XML namespace '<a href="http://schemas.microsoft.com/winfx/2006/xaml" rel="noreferrer">http://schemas.microsoft.com/winfx/2006/xaml</a>'...</strong></p> <p>and</p> <p><strong>Invalid attribute value {x:Static SilverlightApplication3:Page.Test} for property Text. [Line: 7 Position: 25]</strong></p> <p>I'm assuming this is not supported in Silverlight 2, or am I just missing something really simple? Here's the full code for both just in case it's the latter:</p> <pre><code>public partial class Window1 : Window { public static readonly string Test = "test"; public Window1() { InitializeComponent(); } } &lt;Window x:Class="WpfApplication4.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300" xmlns:WpfApplication4="clr-namespace:WpfApplication4"&gt; &lt;Grid&gt; &lt;TextBlock Text="{x:Static WpfApplication4:Window1.Test}" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>and here's the SL version:</p> <pre><code>public partial class Page : UserControl { public static readonly string Test = "test"; public Page() { InitializeComponent(); } } &lt;UserControl x:Class="SilverlightApplication3.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:SilverlightApplication3="clr-namespace:SilverlightApplication3" Width="400" Height="300"&gt; &lt;Grid x:Name="LayoutRoot" Background="White"&gt; &lt;TextBlock Text="{x:Static SilverlightApplication3:Page.Test}" /&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload