2

我正在 WPF 中创建图像滚动条。我使用图像画笔将背景图像设置为网格。滚动图像时,它会闪烁很多。有什么解决办法吗?

代码:

xml:

<Grid Name="ImageGrid">
    <Grid.Background>
        <ImageBrush x:Name="imagebrush"
                Stretch="Fill" TileMode="Tile"
                ViewportUnits="Absolute"/>
    </Grid.Background>
    <Grid.Triggers>
        <EventTrigger RoutedEvent="Loaded">
            <BeginStoryboard HandoffBehavior="Compose">
                <Storyboard>
                    <RectAnimation x:Name="myRectAnimation"   Storyboard.TargetProperty="Background.Viewport" 
                               RepeatBehavior="Forever"/>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Grid.Triggers>
</Grid>

代码隐藏

imagebrush = new ImageBrush();
imagebrush.ImageSource = bmp;

imagebrush.TileMode = TileMode.Tile;

imagebrush.Viewport = new Rect(0, 0, 1024, this.Height);
imagebrush.ViewportUnits = BrushMappingMode.Absolute;


RenderOptions.SetEdgeMode(ImageGrid.Background, EdgeMode.Aliased);

ImageGrid.Height = height;
ImageGrid.Width = width;
ImageGrid.Background = imagebrush;

myRectAnimation.Duration = TimeSpan.FromSeconds(scrollspeed);

myRectAnimation.To = new Rect(-1024, 0, 1024, this.Height);
4

0 回答 0