【问题标题】:Cross fade page transitions Windows phone 8 toolkit交叉淡入淡出页面过渡 Windows phone 8 工具包
【发布时间】:2014-03-28 06:11:33
【问题描述】:

我正在使用 Windows Phone 8 工具包和 Microsoft.Phone.Controls 提供的 TransitionService 实现 NavigationTransition。我期待页面在过渡期间交叉淡入淡出,但默认情况下它们不会交叉淡入淡出。

例如,如果我要使用淡出转换返回上一页,则原始页面会在目标页面出现之前淡化为完全不透明,从而产生“弹出”效果。

我希望有人可以提供指导以实现这种效果。

【问题讨论】:

    标签: windows-phone-8 transitions cross-fade


    【解决方案1】:

    请在 App.xaml.cs 中检查您的 RootFrame 的类型,如果要使用 NavigationTransition,则必须为 TransitionFrame

    【讨论】:

    • 我使用的是TransitionFrame,页面在变化时具有过渡效果,但它们不会交叉淡入淡出,即一次不会有超过一个页面可见 - 因此没有交叉淡入淡出跨度>
    【解决方案2】:

    我最终使用了一些带有屏幕截图和远背景平面的手感,使电话页面看起来“交叉淡入淡出” - 这里有编辑掉的商业细节:

    public class FormPage : PhoneApplicationPage {
        public FormPage() {
            InitializeComponent();
            PrepareAnimationIn(FormApp.frameTransition);
        }
    
        void PrepareAnimationIn(string pageAnimation) {
            AnimatedPageFactory.SetNavigationInTransition(pageAnimation, this);
        }
    
        public void PrepareAnimationOut(string pageAnimation) {
            AnimatedPageFactory.SetNavigationOutTransition(pageAnimation, this);
        }
    
        void StoreScreenShot(string name, WriteableBitmap bitmap) {
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) {
                string path = Path.Combine(screenshotDir, name + screenFileType);
                store.CreateDirectory(screenshotDir);
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Create, store)) {
                    using (BinaryWriter writer = new BinaryWriter(stream)) {
                        int count = bitmap.Pixels.Length * sizeof(int);
                        byte[] pixels = new byte[count];
                        Buffer.BlockCopy(bitmap.Pixels, 0, pixels, 0, count);
                        writer.Write(pixels, 0, pixels.Length);
                    }
                }
            }
        }
    
        WriteableBitmap FetchScreenShot(string name) {
            WriteableBitmap bitmap = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
    
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) {
                string path = Path.Combine(screenshotDir, name + screenFileType);
                if (store.FileExists(path)) {
    
                    using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Open, store)) {
                        using (BinaryReader reader = new BinaryReader(stream)) {
                            int count = bitmap.Pixels.Length * sizeof(int);
                            byte[] pixels = new byte[count];
                            reader.Read(pixels, 0, count);
                            Buffer.BlockCopy(pixels, 0, bitmap.Pixels, 0, count);
                        }
                    }
    
                    store.DeleteFile(path);
                }
            }
            return bitmap;
        }
    
        WriteableBitmap ScreenShot() {
            WriteableBitmap bmpCurrentScreenImage = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
            bmpCurrentScreenImage.Render(_canvas, new MatrixTransform());
            bmpCurrentScreenImage.Invalidate();
            return bmpCurrentScreenImage;
        }
    
        ImageBrush ImageBrushFromBitmap(WriteableBitmap bitmap) {
            return new ImageBrush { ImageSource = bitmap };
        }
    
        static Stack<string> formImages = new Stack<string>();
        static string screenFileType = ".frmscn";
        static string screenshotDir = "frmscrn";
    
        protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) {
    
            var app = Application.Current as App;
    
            if (e.NavigationMode == NavigationMode.New &&
                e.Uri.ToString().Contains("FormPage.xaml")) {
    
                WriteableBitmap screenShot = ScreenShot();
    
                app.RootFrame.Background = ImageBrushFromBitmap(screenShot);
    
                formImages.Push(Name);
                StoreScreenShot(Name, screenShot);
    
            } else if (e.NavigationMode == NavigationMode.Back) {
                if (formImages.Count > 0)
                    app.RootFrame.Background = ImageBrushFromBitmap(FetchScreenShot(formImages.Pop()));
                else {
                    //we're backing out of the last form so reset the background
                    app.RootFrame.Background = null;
                    RemoveCachedScreenshots();
                }
            }
        }
    
        public static void RemoveCachedScreenshots() {
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) {
                string path = Path.Combine(screenshotDir, "*" + screenFileType);
                try {
                    string[] fileList = store.GetFileNames(path);
                    foreach (string f in fileList) {
                        store.DeleteFile(Path.Combine(screenshotDir, f));
                    }
                } catch {
    
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 2011-09-13
      • 1970-01-01
      相关资源
      最近更新 更多