1

これが私のコードです。Windows Phone 8 エミュレーターで実行できます。

  • XAML:

    <Grid x:Name="ContentPanel">
        <ScrollViewer>
            <StackPanel>
                <Button Content="Sample Content" Click="ButtonBase_OnClick">
                    <Button.Style>
                        <Style TargetType="Button">
                            <Setter Property="Width" Value="400"></Setter>
                            <Setter Property="Height" Value="100"></Setter>
                            <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
                            <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="Button">
                                        <Grid>
                                            <Border CornerRadius="10,10,10,10"
                                                    Background="{StaticResource PhoneAccentBrush}"
                                                    BorderBrush="#FF000000" BorderThickness="1,1,1,1"
                                                    x:Name="border" RenderTransformOrigin="0.5,0.5">
                                                <Border.RenderTransform>
                                                    <TransformGroup>
                                                        <ScaleTransform />
                                                        <SkewTransform />
                                                        <RotateTransform />
                                                        <TranslateTransform />
                                                    </TransformGroup>
                                                </Border.RenderTransform>
                                                <ContentPresenter x:Name="contentPresenter"
                                                                  ContentTemplate="{TemplateBinding ContentTemplate}"
                                                                  VerticalAlignment="Center"
                                                                  HorizontalAlignment="Center" />
                                            </Border>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </Button.Style>
                </Button>
                <TextBlock TextWrapping="Wrap">
                    Lorem ipsum Pariatur sint occaecat sunt sint do labore adipisicing 
                    eiusmod incididunt culpa laborum consequat magna dolor labore sunt sed 
                    ullamco anim adipisicing do pariatur ea esse qui sint magna in voluptate 
                    Duis id ut anim id.
                </TextBlock>
            </StackPanel>
        </ScrollViewer>
    </Grid>
    
  • C#:

    private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        var storyb = new Storyboard();
        Duration Show_Duration = new Duration(new TimeSpan(0, 0, 0, 0, 450));
        DoubleAnimation m_OpacityAni = new DoubleAnimation();
        m_OpacityAni.Duration = Show_Duration;
        m_OpacityAni.From = 1.0;
        m_OpacityAni.To = 0.0;
        m_OpacityAni.AutoReverse = true;
    
        storyb.Children.Add(m_OpacityAni);
    
        Storyboard.SetTarget(m_OpacityAni, ContentPanel);
        Storyboard.SetTargetProperty(m_OpacityAni, new PropertyPath("(UIElement.Opacity)"));
    
        storyb.Begin();
    }
    

現在、コンテンツの高さが「ContentPanel」という名前のグリッドよりも小さいため、アニメーションが開始されると、すべてのコンテンツがぼやけずにフェードイン/フェードアウトします。ただし、ScrollViewer を長くする (スクロール可能にする) ためにその TextBlock を複製した場合は、アニメーションを再度実行します。それらのコンテンツは、終了するまでぼやけて表示されます。

ScrollViewer タグを削除すると、すべてのコンテンツがクリアに表示されます。

悪い副作用はありませんが、なぜこのように表示されるのか知りたいです。

あなたの答えを楽しみにしています。ありがとう!

4

1 に答える 1