2011-11-11 38 views
0

我不知道這意味着什麼,但是在我的Windows Phone應用程序(C#)中使用了這一點XAML,它給了我錯誤「鍵屬性只能用於包含在IDictionary類型屬性中的標記。鍵屬性只能用於包含在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> 

回答

2

x:Key指定的物品的在字典中的關鍵。

您只能在進入字典的標記中使用它,例如在<Resources>集合中。

+0

那麼我該如何解決它......?它說我應該這樣包裝它:' '但是,錯誤,因爲已經有'phone:PhoneApplicaitonPage'部分,並且如果我將'.Resources'添加到存在的'.Resources',它也會導致錯誤。 – JacobTheDev

+1

您需要將其添加到現有的'phone:PhoneApplicationPage.Resources>',就像其他任何資源一樣。 'Resources'是'PhoneApplicationPage'的一個屬性,它只能被設置一次(就像XAML中的其他屬性一樣)。 – SLaks

+0

你可以在這裏摘錄你的整個xaml嗎? – Jeff

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> 
+0

嗨,歡迎來到SO,我正在評論新用戶發佈的」第一個答案「,當您離開答案時,請添加一些解釋。 –

相關問題