Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to set your <code>DataContext</code>. </p> <pre><code>public MyPage() { DataContext = new colors(); } </code></pre> <p>I prefer to do it in XAML. </p> <p>Import your namespace at the top</p> <pre><code>xmlns:vm="clr-namespace:MyNamespace" </code></pre> <p>Add the class as a resource (you can do this at app level if you prefer)</p> <pre><code>&lt;phone:PhoneApplicationPage.Resources&gt; &lt;vm:colors x:Key="vmColors" /&gt; &lt;/phone:PhoneApplicationPage.Resources&gt; </code></pre> <p>Assign to the DataContext (in this case I've assigned it to the Grid so any control within the Grid will assume the <code>vmColors</code> DataContext, unless you change it for that particular child control).</p> <pre><code>&lt;Grid DataContext="{StaticResource vmColors}"&gt; &lt;Rectangle Fill="{Binding Gray}" /&gt; &lt;/Grid&gt; </code></pre> <p>Here's the full XAML for a page so you can see where the code goes.</p> <pre><code>&lt;phone:PhoneApplicationPage x:Class="MyClass.MyPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:vm="clr-namespace:MyNamespace" // &lt;&lt; IMPORT NAMESPACE xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" mc:Ignorable="d"&gt; //ALLOW THE CLASS TO BE ACCESSED VIA STATICRESOURCE &lt;phone:PhoneApplicationPage.Resources&gt; &lt;vm:colors x:Key="vmColors"/&gt; &lt;/phone:PhoneApplicationPage.Resources&gt; &lt;Grid x:Name="LayoutRoot" Background="Transparent"&gt; //SET THE DATACONTEXT OF THE GRID TO THE COLORS CLASS &lt;Grid DataContext="{StaticResource vmColors}"&gt; &lt;Rectangle Fill="{Binding Gray}" /&gt; &lt;/Grid&gt; &lt;/Grid&gt; &lt;/phone:PhoneApplicationPage&gt; </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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