C# 查找资源字典时发生windows phone错误

C# 查找资源字典时发生windows phone错误,c#,windows-phone-8,dictionary,C#,Windows Phone 8,Dictionary,因此,我正在创建通用windows phone应用程序。我正在尝试更改pivot标题面板中单击项目的颜色。我已使用以下语法在windows phone项目中添加了style.axml文件: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

因此,我正在创建通用windows phone应用程序。我正在尝试更改pivot标题面板中单击项目的颜色。我已使用以下语法在windows phone项目中添加了style.axml文件:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:FacilityAppWindowsPhone">

    <Style x:Key="CustomPivotStyle" TargetType="Pivot">
        <Setter Property="Margin" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Foreground" Value="{ThemeResource PhoneForegroundBrush}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <Grid/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Pivot">
                    <Grid x:Name="RootElement" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="Orientation">
                                <VisualState x:Name="Portrait">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="TitleContentControl">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource PivotPortraitThemePadding}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Landscape">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="TitleContentControl">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource PivotLandscapeThemePadding}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <ContentControl x:Name="TitleContentControl" ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" Style="{StaticResource PivotTitleContentControlStyle}"/>
                        <ScrollViewer x:Name="ScrollViewer" HorizontalSnapPointsAlignment="Center" HorizontalSnapPointsType="MandatorySingle" HorizontalScrollBarVisibility="Hidden" Margin="{TemplateBinding Padding}" Grid.Row="1" Template="{StaticResource ScrollViewerScrollBarlessTemplate}" VerticalSnapPointsType="None" VerticalScrollBarVisibility="Disabled" VerticalScrollMode="Disabled" VerticalContentAlignment="Stretch" ZoomMode="Disabled">
                            <PivotPanel x:Name="Panel" VerticalAlignment="Stretch">
                                <PivotHeaderPanel x:Name="Header" Background="{TemplateBinding BorderBrush}">
                                    <PivotHeaderPanel.RenderTransform>
                                        <CompositeTransform x:Name="HeaderTranslateTransform" TranslateX="0"/>
                                    </PivotHeaderPanel.RenderTransform>
                                </PivotHeaderPanel>
                                <ItemsPresenter x:Name="PivotItemPresenter">
                                    <ItemsPresenter.RenderTransform>
                                        <TranslateTransform x:Name="ItemsPresenterTranslateTransform" X="0"/>
                                    </ItemsPresenter.RenderTransform>
                                </ItemsPresenter>
                            </PivotPanel>
                        </ScrollViewer>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

在共享项目的App.xaml文件中,我试图添加这段代码

<ResourceDictionary x:Key="Dictionary">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Styling.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>


但是我发现错误“En error occurrent when finding the resource dictionary”styleing.axml.

您需要为通用应用程序引用这样的字典(假设字典位于共享项目中):


如果你想了解更多细节,我最近在博客上写过:

所以我放弃了这种方法,这就是我在代码中解决它的方法: 在.xaml文件中,在Pivot标记中添加此属性:SelectionChanged=“MyPivot\u SelectionChanged”

而不是在代码中:

 private void MyPivot_SelectionChanged(object sender,    SelectionChangedEventArgs e)
        {
            foreach (PivotItem pivotItem in MyPivot.Items)
            {
                if (pivotItem == MyPivot.Items[MyPivot.SelectedIndex])
                {
                    //selected
                   ((TextBlock)pivotItem.Header).Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255,31, 93, 184));
                }
                else
                {
                     // not selected
                    ((TextBlock)pivotItem.Header).Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255,109, 162, 240 ));
                 }
             }
         }

您的style.xaml文件是否在根文件夹中?并尝试从ResourceDictionary标记中删除x:Key=“Dictionary”…这是项目的结构..当我尝试删除键时,它会说“每个字典必须具有和关联的键”“您是在创建通用应用程序还是仅创建WINDOWS PHONE 8.1应用程序?这个style.xaml ResourceDictionary在两个应用程序中都使用,或者仅在windows phone应用程序中使用?我正在制作通用应用程序(但目前我只使用手机版本)…它仅在windows phone应用程序中使用..您有什么想法吗?阅读此文,
 private void MyPivot_SelectionChanged(object sender,    SelectionChangedEventArgs e)
        {
            foreach (PivotItem pivotItem in MyPivot.Items)
            {
                if (pivotItem == MyPivot.Items[MyPivot.SelectedIndex])
                {
                    //selected
                   ((TextBlock)pivotItem.Header).Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255,31, 93, 184));
                }
                else
                {
                     // not selected
                    ((TextBlock)pivotItem.Header).Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255,109, 162, 240 ));
                 }
             }
         }