简体   繁体   English

如何在Silverlight 4中从WebBrowser控件平滑过渡到图像?

[英]How to make smooth transition from a WebBrowser control to an Image in Silverlight 4?


I have the following XAML on my page: 我的页面上有以下XAML:

<Grid x:Name="LayoutRoot">  
        <Viewbox Stretch="Uniform">  
        <Image x:Name="myImage" />  
    </Viewbox>  
    <WebBrowser x:Name="myBrowser"  />  
</Grid>

and then in the codebehind I'm switching the visibility between the image and the browser content: 然后在后面的代码中,在图像和浏览器内容之间切换可见性:

myBrowser.Visibility = Visibility.Collapsed;  
            myImage.Source = new BitmapImage(new Uri(p));  
            myImage.Visibility = Visibility.Visible;

and

myImage.Visibility = Visibility.Collapsed;  
            myBrowser.Source = new Uri(myPath + p, UriKind.Absolute);  
            myBrowser.Visibility = Visibility.Visible;

This works fine, but what the client now wants is a smooth transition between when the Image is shown and when the browser is shown. 这可以正常工作,但是客户端现在需要的是在显示图像和显示浏览器之间的平滑过渡。 I tried several approaches but always ran into dead end. 我尝试了几种方法,但是总是遇到死胡同。 Do you have any ideas? 你有什么想法?

I tried setting two states using the VSM and than displaying a white rectangle on top as an overlay, before the swap takes place, but that didn't work (I guess it's because nothing can be placed above the WebBrowser?) I tried setting the Visibility of the image control and the webbrowser control using the VSM, but that didn't work either. 我尝试使用VSM设置两个状态,然后在交换发生之前在顶部显示一个白色矩形作为覆盖,但这没用(我想是因为WebBrowser上方无法放置任何东西?),我尝试设置了使用VSM的图像控件和Web浏览器控件的可见性,但这也不起作用。 I really don't know what else to try to solve this simple task. 我真的不知道还有什么尝试解决这个简单的任务的。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

If you're looking for a "smooth" transition that you might want to try fading the controls in and out. 如果您正在寻找“平稳”过渡,则可能需要尝试使控件淡入淡出。 Animate the Opacity of each object. 对每个对象的不透明度进行动画处理。 For example, set the opacity of the ViewBox to zero and the opacity of the image to 100. Then animate the opacity property of both objects. 例如,将ViewBox的不透明度设置为零,将图像的不透明度设置为100。然后为两个对象的不透明度属性设置动画。

The end-result will be a smooth transition from one object to the other. 最终结果将是从一个对象到另一个对象的平滑过渡。

Here is an MSDN article to get you started: Animation Overview 这是MSDN文章,可以帮助您入门: 动画概述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM