Note that there are some explanatory texts on larger screens.

plurals
  1. POruntime Exception when binding to a datacontext of a user control
    text
    copied!<p>Here is the XAML for the main page.</p> <pre><code>&lt;StackPanel x:Name="menuStackPanel" Grid.Row="4" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"&gt; &lt;StackPanel.DataContext&gt; &lt;Model:GameSettings/&gt; &lt;/StackPanel.DataContext&gt; &lt;uilibrary:CustomImageButton x:Name="btnPlay" Scale="1.5" ReadyImage="/App;component/Images/Menus/menu_play.png" SelectedImage="/App;component/Images/Menus/menu_play_selected.png" Margin="5"/&gt; &lt;uilibrary:CustomImageButton x:Name="btnPlanet" StickyState="True" Scale="1.5" ReadyImage="/App;component/Images/Menus/menu_planet.png" SelectedImage="/App;component/Images/Menus/menu_planet_selected.png" AIsSelected="{Binding Path=UsePlanet, Mode=TwoWay, ElementName=menuStackPanel}" Margin="5"&gt; &lt;/uilibrary:CustomImageButton&gt; &lt;uilibrary:CustomImageButton x:Name="btnGravity" StickyState="True" Scale="1.5" ReadyImage="/App;component/Images/Menus/menu_gravity.png" SelectedImage="/App;component/Images/Menus/menu_gravity_selected.png" AIsSelected="True" Margin="5"&gt; &lt;/uilibrary:CustomImageButton&gt; &lt;/StackPanel&gt; </code></pre> <p>Here is the XAML for the UserControl 'CustomImageButon'</p> <pre><code>&lt;UserControl x:Class="UILibrary.CustomImageButton" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" d:DesignHeight="480" d:DesignWidth="480"&gt; &lt;Grid x:Name="LayoutRoot" Background="Transparent"&gt; &lt;Image x:Name="MyImage" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center"&gt; &lt;Image.RenderTransform&gt; &lt;CompositeTransform x:Name="buttonTransform"/&gt; &lt;/Image.RenderTransform&gt; &lt;/Image&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>Here is the code for the UsePlanet property, the value of 'MyUsePlanet' defaults to false.</p> <pre><code>public bool UsePlanet { get { return MyUsePlanet; } set { MyUsePlanet = value; IsolatedStorageSettings.ApplicationSettings[GameSettings.key_planet] = value; IsolatedStorageSettings.ApplicationSettings.Save(); this.OnPropertyChanged("UsePlanet"); } } </code></pre> <p>Here is my Exception information</p> <pre><code>A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll 'UI Task' (Managed): Loaded 'System.SR.dll' A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll A first chance exception of type 'MS.Internal.NativeParseException' occurred in System.Windows.dll A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.dll An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.dll Additional information: Set property 'UILibrary.CustomImageButton.AIsSelected' threw an exception. [Line: 95 Position: 46] </code></pre> <p>I know it has something to do with <code>AIsSelected="{Binding Path=UsePlanet, Mode=TwoWay, ElementName=menuStackPanel}"</code> because if I just set it to "True" then the problem goes away but I would like it bound to my model. Also other bindings such as this one work just fine.</p> <pre><code>&lt;TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24" Text="{Binding ShipAScore}"&gt; &lt;TextBlock.DataContext&gt; &lt;Model:Scores/&gt; &lt;/TextBlock.DataContext&gt; &lt;/TextBlock&gt; </code></pre> <p><strong>UDATE 4/28/2013</strong> Adding a Dependency Property to the code behind of my UserControl solved this issue.</p> <pre><code>public static readonly DependencyProperty AIsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(CustomImageButton), new PropertyMetadata(false)); </code></pre>
 

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