メイン ページの XAML は次のとおりです。
<StackPanel x:Name="menuStackPanel" Grid.Row="4" Grid.ColumnSpan="2"
Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel.DataContext>
<Model:GameSettings/>
</StackPanel.DataContext>
<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"/>
<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">
</uilibrary:CustomImageButton>
<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">
</uilibrary:CustomImageButton>
</StackPanel>
UserControl 'CustomImageButon' の XAML は次のとおりです。
<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">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Image x:Name="MyImage" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center">
<Image.RenderTransform>
<CompositeTransform x:Name="buttonTransform"/>
</Image.RenderTransform>
</Image>
</Grid>
</UserControl>
UsePlanet プロパティのコードは次のとおりです。'MyUsePlanet' の値はデフォルトで false に設定されています。
public bool UsePlanet
{
get
{
return MyUsePlanet;
}
set
{
MyUsePlanet = value;
IsolatedStorageSettings.ApplicationSettings[GameSettings.key_planet] = value;
IsolatedStorageSettings.ApplicationSettings.Save();
this.OnPropertyChanged("UsePlanet");
}
}
ここに私の例外情報があります
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]
AIsSelected="{Binding Path=UsePlanet, Mode=TwoWay, ElementName=menuStackPanel}"
「True」に設定すると問題は解決しますが、モデルにバインドしたいので、何か関係があることはわかっています。このような他のバインディングも問題なく動作します。
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24" Text="{Binding ShipAScore}">
<TextBlock.DataContext>
<Model:Scores/>
</TextBlock.DataContext>
</TextBlock>
UDATE 2013 年 4 月 28 日 UserControl のコード ビハインドに依存関係プロパティを追加すると、この問題が解決しました。
public static readonly DependencyProperty AIsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(CustomImageButton), new PropertyMetadata(false));