条状闪烁

时间:2018-11-19 01:04:05

标签: wpf xaml

我在下面有XAML代码,但它不平滑,偶尔会产生闪烁。如何在XAML中改进此功能?我尝试了多种解决方案,但似乎总是在一分钟内多次产生闪烁。这是因为显示器和源代码的帧频吗?请帮忙。如果您有使光滑的例子,我将不胜感激。

<Window x:Class="BarsTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:BarsTest"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel Orientation="Horizontal" Background="Black">
            <Rectangle Height="1080" Width="160" Fill="White">
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="AnimatedTranslateTransform0" X="-160" Y="0" />
                </Rectangle.RenderTransform>
            </Rectangle>
            <Rectangle Height="1080" Width="160" Fill="White">
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="AnimatedTranslateTransform1" X="160" Y="0" />
                </Rectangle.RenderTransform>
            </Rectangle>
            <Rectangle Height="1080" Width="160" Fill="White">
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="AnimatedTranslateTransform2" X="480" Y="0" />
                </Rectangle.RenderTransform>
            </Rectangle>
            <Rectangle Height="1080" Width="160" Fill="White">
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="AnimatedTranslateTransform3" X="800" Y="0" />
                </Rectangle.RenderTransform>
            </Rectangle>
            <Rectangle Height="1080" Width="160" Fill="White">
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="AnimatedTranslateTransform4" X="1120" Y="0" />
                </Rectangle.RenderTransform>
            </Rectangle>
            <Rectangle Height="1080" Width="160" Fill="White">
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="AnimatedTranslateTransform5" X="1440" Y="0" />
                </Rectangle.RenderTransform>
            </Rectangle>
            <Rectangle Height="1080" Width="160" Fill="White">
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="AnimatedTranslateTransform6" X="1760" Y="0" />
                </Rectangle.RenderTransform>
            </Rectangle>

            <StackPanel.Triggers>
                <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                    <BeginStoryboard Name="myBeginStoryboard">
                        <Storyboard DesiredFrameRate="60">
                            <DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform0" Storyboard.TargetProperty="X" From="-160" To="160" Duration="0:0:0.5"/>
                            <DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform1" Storyboard.TargetProperty="X" From="0" To="320" Duration="0:0:0.5"/>
                            <DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform2" Storyboard.TargetProperty="X" From="160" To="480" Duration="0:0:0.5" />
                            <DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform3" Storyboard.TargetProperty="X" From="320" To="640" Duration="0:0:0.5" />
                            <DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform4" Storyboard.TargetProperty="X" From="480" To="800" Duration="0:0:0.5" />
                            <DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform5" Storyboard.TargetProperty="X" From="640" To="960" Duration="0:0:0.5" />
                            <DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="AnimatedTranslateTransform6" Storyboard.TargetProperty="X" From="800" To="1120" Duration="0:0:0.5" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </StackPanel.Triggers>
        </StackPanel>
    </Grid>
</Window>

溴 阿鲁斯

0 个答案:

没有答案