我不知道这意味着什么,但是在我的Windows Phone应用程序(C#)中使用了这个XAML,它给了我错误“Key属性只能用于IDictionary类型属性中包含的标记。”
<local:Settings x:Key="appSettings"></local:Settings>
有什么想法吗?
编辑:将此作为参考:http://msdn.microsoft.com/en-us/library/ff769510(v=vs.92).aspx
根据要求:
<phone:PhoneApplicationPage
x:Class="Google_.Settings"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Google_"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Margin="12,20,0,25">
<TextBlock x:Name="ApplicationTitle" Text="GOOGLE+" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="settings" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<CheckBox Content="Warning on exit" Grid.Row="1" Height="72" HorizontalAlignment="Left" Margin="12,0,0,0" Name="exitAlert" VerticalAlignment="Top" Width="456" IsChecked="{Binding Source={StaticResource appSettings}, Path=CheckBoxSetting, Mode=TwoWay}"/>
<!--<CheckBox Content="Enable location data" Grid.Row="1" Height="72" HorizontalAlignment="Left" Margin="12,72,0,0" Name="location" VerticalAlignment="Top" Width="456" IsChecked="True" />
<CheckBox Content="Lock orienation to portrait" Grid.Row="1" Height="72" HorizontalAlignment="Left" Margin="12,144,0,0" Name="orientation" VerticalAlignment="Top" Width="456" />-->
<local:Settings x:Key="appSettings"></local:Settings>
</Grid>
</phone:PhoneApplicationPage>
答案 0 :(得分:3)
x:Key
指定字典中项目的键。
您只能在进入字典的标记中使用它,例如在<Resources>
集合内。
答案 1 :(得分:0)
<!--Try this -->
<phone:PhoneApplicationPage
x:Class="Google_.Settings"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Google_"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<local:Settings x:Key="appSettings"></local:Settings>
</phone:PhoneApplicationPage.Resources>
<!--Your code -->
</phone:PhoneApplicationPage>