Пример #1
0
        private static void Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (IsoStoreImageSource._cacheDict == null)
            {
                IsoStoreImageSource._cacheDict = new Dictionary <string, byte[]>();
            }
            Image img = d as Image;

            if (img == null)
            {
                return;
            }
            string path = e.NewValue as string;

            if (string.IsNullOrEmpty(path))
            {
                img.Source = null;
            }
            else if (IsoStoreImageSource._cacheDict.ContainsKey(path))
            {
                MemoryStream memoryStream = new MemoryStream(IsoStoreImageSource._cacheDict[path]);
                IsoStoreImageSource.SetSource(img, (Stream)memoryStream);
                memoryStream.Close();
            }
            else
            {
                SynchronizationContext uiThread = SynchronizationContext.Current;
                Task.Factory.StartNew((Action)(() =>
                {
                    try
                    {
                        using (IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication())
                        {
                            if (!storeForApplication.FileExists(path))
                            {
                                return;
                            }
                            IsolatedStorageFileStream stream = storeForApplication.OpenFile(path, FileMode.Open, FileAccess.Read);
                            uiThread.Post((SendOrPostCallback)(_ =>
                            {
                                if (IsoStoreImageSource.CurrentCacheSize < IsoStoreImageSource.MAX_CACHE_SIZE)
                                {
                                    IsoStoreImageSource._cacheDict[path] = StreamUtils.ReadFullyToByteArray((Stream)stream);
                                    IsoStoreImageSource.CurrentCacheSize += IsoStoreImageSource._cacheDict[path].Length;
                                }
                                stream.Position = 0L;
                                if (IsoStoreImageSource.GetIsoStoreFileName((UIElement)img) == path)
                                {
                                    IsoStoreImageSource.SetSource(img, (Stream)stream);
                                }
                                stream.Close();
                            }), null);
                        }
                    }
                    catch
                    {
                    }
                }));
            }
        }
Пример #2
0
        protected override void GenerateChildren()
        {
            base.GenerateChildren();
            Image  image1 = new Image();
            double width  = this.Width;

            ((FrameworkElement)image1).Width = width;
            double fixedHeight = this.FixedHeight;

            ((FrameworkElement)image1).Height = fixedHeight;
            Image image2 = image1;

            ((UIElement)image2).Tap += (new EventHandler <System.Windows.Input.GestureEventArgs>(this.image_Tap));
            IsoStoreImageSource.SetIsoStoreFileName((UIElement)image2, this._isHorizontal ? this._horSpriteDescription.SpritePath : this._vertSpriteDescription.SpritePath);
            this.Children.Add((FrameworkElement)image2);
        }