WPF(图像滚动条)

时间:2014-02-24 06:41:53

标签: wpf imagebrush

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

代码:

的Xaml:

<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);

0 个答案:

没有答案