How to use gif animated image in WP 7

后端 未结 1 634
感情败类
感情败类 2021-01-25 18:30

I have seen this post: Display GIF in a WP7 application with Silverlight

But in my case? for animating I am using a popup. So when application starts it shows a popup fo

相关标签:
1条回答
  • 2021-01-25 18:43

    Finally working... Talk about events conspiring against you... You need to fix all these things first!

    (note there is a following problem with only the first 2 frames being animated but that is for another question):

    Part 6 (getting sleepy now)

    Lastly relative image URLs starting with "/" are not supported by the ImageTools.Controls.ImageConverter, so you need to use a relative URL without the leading "/". I found that once every other problem was fixed I was getting an unsupported exception with the path.

            ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
            InitializeComponent();
            this.ImageSource = new Uri("layer1.gif", UriKind.Relative);
            this.DataContext = this;
    

    Part 5

    You need to set the binding DataContext somewhere.

    You do not connect the XAML page DataContext to the code behind object. I could not see where you had done this. A very simple/quick way is to set this.DataContext = this; in the page's constructor.

    Part 4

    You can only bind to public properties!

    Your ImageSource property is currently protected. Change it to Public

        public Uri ImageSource
        {
            get;
            set;
        }
    

    Part 3

    I also note your ImageSource property is not an INotifyPropertyChange type property. So setting it after InitializeComponent will not work.

    Try it this way round (or change it to use a notify property):

    public AnimatedSplashScreen()
    {
       ImageSource =
            new Uri(
                "/200px-Sunflower_as_GIF.gif",
                UriKind.Relative);
        ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
        InitializeComponent();
    }
    

    Part 2 (actually not support by ImageTools.Controls.ImageConverter)

    The cross domain file was apparently only one problem. Based on the comments you also need to store your images on your own website and reference them with an appropriate URI format.

    If you put your files in a folder called images under ClientBin you use this format:

    "/images/imagename.jpg"
    

    This is the best option as the images also use Browser caching!

    For your example it would be like this:

        ImageSource =
                    new Uri(
                        "/images/200px-Sunflower_as_GIF.gif",
                        UriKind.Relative);
                ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
    

    and put the example file in your client bin folder under images.

    If you do not use the leading "/" Silverlight assumes the files are resources in the current module instead e.g.

    "images/imagename.jpg"
    

    Part 1

    This is actually a copyright issue, to stop people deep-linking files from other people's sites without permission.

    The Wikimedia.org site does not have any cross domain access files e.g.:

    • http://upload.wikimedia.org/crossdomain.xml
    • http://upload.wikimedia.org/crossdomainpolicy.xml
    • wikimedia.org/crossdomain.xml
    • wikimedia.org/crossdomainpolicy.xml

    ... presumably as they do not want others to use the files they host there outside of their own website.

    That means Silverlight will not allow access to files on those sites as it is a good Internet citizen. Try hosting the files on your own site (where your Silverlight app resides), then it will not need any cross domain access file at all.

    Side note: If you do ever need a cross domain file on a website, for use by Silverlight, use a crossdomainpolicy.xml as the other one is not as useful (designed for older flash use)

    0 讨论(0)
提交回复
热议问题