0

我想更改 的边框颜色,LoopingSelector所以我将 Generic.xaml 的样式定义LoopingSelectorItem(如下所列)复制到我的PhoneApplicationPage.Resources. 然后将Fillof更改GridRed.

现在的问题是,当我在模拟器中打开这个应用程序时,LoopingSelector并没有立即出现。但是只要我触摸选择器应该所在的屏幕区域,它就会显示出来,并且边框颜色就是我想要的。这看起来像一个初始化问题,但我不知道该怎么做。我尝试复制此样式定义,而不对原始 Generic.xaml 进行任何更改,但问题仍然存在。任何人都可以帮助我解决这个问题吗?

  <phone:PhoneApplicationPage.Resources>

    <Style TargetType="primitives:LoopingSelectorItem">
        <Setter Property="Foreground" Value="{StaticResource PhoneSubtleBrush}"/>
        <Setter Property="Padding" Value="6"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Border x:Name="root" CacheMode="BitmapCache" Background="Transparent" Padding="{TemplateBinding Padding}">

                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">

                                <VisualStateGroup.Transitions>
                                    <VisualTransition From="Normal" To="Expanded" GeneratedDuration="0:0:0.33" />
                                    <VisualTransition From="Expanded" To="Normal" GeneratedDuration="0:0:0.33" />
                                </VisualStateGroup.Transitions>

                                <VisualState x:Name="Normal" />

                                <VisualState x:Name="Expanded">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="border" Storyboard.TargetProperty="Opacity" To="0.8" Duration="0"/>
                                    </Storyboard>
                                </VisualState>

                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="background" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
                                        <DoubleAnimation Storyboard.TargetName="border" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="border" Storyboard.TargetProperty="BorderBrush" Duration="0">
                                            <ObjectAnimationUsingKeyFrames.KeyFrames>
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
                                            </ObjectAnimationUsingKeyFrames.KeyFrames>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="contentControl" Storyboard.TargetProperty="Foreground" Duration="0">
                                            <ObjectAnimationUsingKeyFrames.KeyFrames>
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="White" />
                                            </ObjectAnimationUsingKeyFrames.KeyFrames>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>

                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Border.RenderTransform>
                            <TranslateTransform x:Name="Transform"/>
                        </Border.RenderTransform>

                        <Grid>
                            <Rectangle x:Name="background" Margin="0" Opacity="0" Fill="Red" CacheMode="BitmapCache"/>

                            <Border x:Name="border" Opacity="0" BorderThickness="3" BorderBrush="{StaticResource PhoneSubtleBrush}">
                                <ContentControl x:Name="contentControl" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch">
                                    <ContentPresenter x:Name="contentPresenter" CacheMode="BitmapCache"/>
                                </ContentControl>
                            </Border>
                        </Grid>

                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</phone:PhoneApplicationPage.Resources>
4

1 回答 1

0

我刚刚发现自己遇到了同样的问题。我绕过它的方法是从 Toolkit 的源代码中获取 LoopingSelector 和 LoopingSelectorItem 代码,将它们重命名为 CustomLoopingSelector 和 CustomLoopingSelectorItem。然后在我的generic.xaml 中,但是Toolkit 的默认样式为LoopingSelector,但随后将我想要的LoopingSelectorItem 的样式添加为CustomLoopingSelectorItem 的默认样式。

现在,这给了我想要的样式,并且在返回页面时不会空白。对你来说可能值得一试。

于 2014-04-12T07:15:53.853 回答