zoukankan      html  css  js  c++  java
  • winrt 上的翻书特效组件 源码分享 转载请说明

    http://blog.csdn.net/wangrenzhu2011/article/details/10207413 (转)

    [csharp] view plaincopyprint?
     
    1. [TemplatePart(Name = A_PARTNAME, Type = typeof(Border))]  
    2. [TemplatePart(Name = B_PARTNAME, Type = typeof(Border))]  
    3. [TemplatePart(Name = C_PARTNAME, Type = typeof(Border))]  
    4. [TemplatePart(Name = D_PARTNAME, Type = typeof(Border))]  
    5. [TemplatePart(Name = E_PARTNAME, Type = typeof(Border))]  
    6. [TemplatePart(Name = F_PARTNAME, Type = typeof(Border))]  
    7. [TemplatePart(Name = A_RECT_PARTNAME, Type = typeof(RectangleGeometry))]  
    8. [TemplatePart(Name = B_RECT_PARTNAME, Type = typeof(RectangleGeometry))]  
    9. [TemplatePart(Name = C_RECT_PARTNAME, Type = typeof(RectangleGeometry))]  
    10. [TemplatePart(Name = D_RECT_PARTNAME, Type = typeof(RectangleGeometry))]  
    11. [TemplatePart(Name = E_RECT_PARTNAME, Type = typeof(RectangleGeometry))]  
    12. [TemplatePart(Name = F_RECT_PARTNAME, Type = typeof(RectangleGeometry))]  
    13. [TemplatePart(Name = A_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    14. [TemplatePart(Name = B_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    15. [TemplatePart(Name = C_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    16. [TemplatePart(Name = D_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    17. [TemplatePart(Name = E_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    18. [TemplatePart(Name = F_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    19. [TemplatePart(Name = A_PRESENTER_PARTNAME, Type = typeof(ContentPresenter))]  
    20. [TemplatePart(Name = B_PRESENTER_PARTNAME, Type = typeof(ContentPresenter))]  
    21. [TemplatePart(Name = C_PRESENTER_PARTNAME, Type = typeof(ContentPresenter))]  
    22. [TemplatePart(Name = D_PRESENTER_PARTNAME, Type = typeof(ContentPresenter))]  
    23. [TemplatePart(Name = E_PRESENTER_PARTNAME, Type = typeof(ContentPresenter))]  
    24. [TemplatePart(Name = F_PRESENTER_PARTNAME, Type = typeof(ContentPresenter))]  
    25. [TemplatePart(Name = INNER_LEFT_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    26. [TemplatePart(Name = OUTER_LEFT_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    27. [TemplatePart(Name = INNER_RIGHT_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    28. [TemplatePart(Name = OUTER_RIGHT_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    29. [TemplatePart(Name = MARGIN_LEFT_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    30. [TemplatePart(Name = MARGIN_RIGHT_TRANS_PARTNAME, Type = typeof(CompositeTransform))]  
    31. [TemplatePart(Name = ST_SHADOW_SPLIT_INNER_LEFT_PARTNAME, Type = typeof(StackPanel))]  
    32. [TemplatePart(Name = ST_SHADOW_SPLIT_OUTER_LEFT_PARTNAME, Type = typeof(StackPanel))]  
    33. [TemplatePart(Name = ST_SHADOW_SPLIT_INNER_RIGHT_PARTNAME, Type = typeof(StackPanel))]  
    34. [TemplatePart(Name = ST_SHADOW_SPLIT_OUTER_RIGHT_PARTNAME, Type = typeof(StackPanel))]  
    35. [TemplatePart(Name = ST_SHADOW_MARGIN_LEFT_PARTNAME, Type = typeof(StackPanel))]  
    36. [TemplatePart(Name = ST_SHADOW_MARGIN_RIGHT_PARTNAME, Type = typeof(StackPanel))]  
    37. [TemplatePart(Name = BOOK_CONTAINER_PARTNAME, Type = typeof(Image))]  
    38. [TemplatePart(Name = GRD_CONTENT_PARTNAME, Type = typeof(Grid))]  
    39. /// <summary>  
    40. /// 作者:王韧竹  
    41. /// 版本:1.1  
    42. /// 根据偏移量算法 计算是否为放大 或者翻页 保证两者不冲突。  
    43. /// 18/6/2013 23:06  
    44. /// windows8 翻书特效组件  
    45. /// </summary>  
    46. public sealed class FlipBookControl : ItemsControl  
    47. {  
    48.     #region Member Variables  
    49.     /// <summary>  
    50.     /// 0 初始 翻页状态1 翻页状态2  
    51.     /// </summary>  
    52.     private int Status = 0;  
    53.     /// <summary>  
    54.     /// 是否翻下一页  
    55.     /// true 下一页 false 上一页  
    56.     /// </summary>  
    57.     private bool isNext = false;  
    58.     /// <summary>  
    59.     /// 触发向左翻页动画  
    60.     /// true 发生偏移  false 停止偏移  
    61.     /// </summary>  
    62.     private bool turnLeft = false;  
    63.     /// <summary>  
    64.     /// 触发向右翻页动画  
    65.     /// true 发生偏移  false 停止偏移  
    66.     /// </summary>  
    67.     private bool turnRight = false;  
    68.     /// <summary>  
    69.     /// 触发向右翻页还原动画  
    70.     /// true 发生偏移  false 停止偏移  
    71.     /// </summary>  
    72.     private bool rightRestore = false;  
    73.     /// <summary>  
    74.     /// 触发向左翻页还原动画  
    75.     /// true 发生偏移  false 停止偏移  
    76.     /// </summary>  
    77.     private bool leftRestore = false;  
    78.     /// <summary>  
    79.     /// 是否多点操作中  
    80.     /// true 是 false 否  
    81.     /// </summary>  
    82.     private bool isManipulating = false;  
    83.     /// <summary>  
    84.     /// 最近一次偏移量  
    85.     /// </summary>  
    86.     private double lastDeltaOffset = 0.0;  
    87.     /// <summary>  
    88.     /// 横向偏移量  
    89.     /// </summary>  
    90.     private double offsetWidth = 0.0;  
    91.     /// <summary>  
    92.     /// 竖向偏移量  
    93.     /// </summary>  
    94.     private double offsetHeight = 0.0;  
    95.     /// <summary>  
    96.     /// 是否加载  
    97.     /// </summary>  
    98.     private bool isLoaded = false;  
    99.     /// <summary>  
    100.     /// 是否初始化  
    101.     /// </summary>  
    102.     private bool isInit = false;  
    103.   
    104.     /// <summary>  
    105.     /// 控制是否翻页  
    106.     /// </summary>  
    107.     private bool isFlip = true;  
    108.   
    109.     /// <summary>  
    110.     /// 是否释放  
    111.     /// </summary>  
    112.     private bool isRelease = true;  
    113.     Border nextPage;  
    114.     Border prevPage;  
    115.     Border leftPage;  
    116.     Border rightPage;  
    117.     Border leftTopPage;  
    118.     Border rightTopPage;  
    119.     CompositeTransform nextTrans;  
    120.     CompositeTransform prevTrans;  
    121.     Border A;  
    122.     Border B;  
    123.     Border C;  
    124.     Border D;  
    125.     Border E;  
    126.     Border F;  
    127.     ContentPresenter APresenter;  
    128.     ContentPresenter BPresenter;  
    129.     ContentPresenter CPresenter;  
    130.     ContentPresenter DPresenter;  
    131.     ContentPresenter EPresenter;  
    132.     ContentPresenter FPresenter;  
    133.     RectangleGeometry ARect;  
    134.     RectangleGeometry BRect;  
    135.     RectangleGeometry CRect;  
    136.     RectangleGeometry DRect;  
    137.     RectangleGeometry ERect;  
    138.     RectangleGeometry FRect;  
    139.     CompositeTransform transA;  
    140.     CompositeTransform transB;  
    141.     CompositeTransform transC;  
    142.     CompositeTransform transD;  
    143.     CompositeTransform transE;  
    144.     CompositeTransform transF;  
    145.     CompositeTransform innerLeftTrans;  
    146.     CompositeTransform outerLeftTrans;  
    147.     CompositeTransform innerRightTrans;  
    148.     CompositeTransform outerRightTrans;  
    149.     CompositeTransform marginLeftTrans;  
    150.     CompositeTransform marginRightTrans;  
    151.     StackPanel stShadowSplitOuterLeft;  
    152.     StackPanel stShadowSplitInnerLeft;  
    153.     StackPanel stShadowSplitOuterRight;  
    154.     StackPanel stShadowSplitInnerRight;  
    155.     StackPanel stShadowMarginLeft;  
    156.     StackPanel stShadowMarginRight;  
    157.     Grid grdContent;  
    158.     Image bookContainer;  
    159.     ImageBrush leftBrush;  
    160.     ImageBrush rightBrush;  
    161.     private TransformGroup _transformGroup;  
    162.     private MatrixTransform _previousTransform;  
    163.     private CompositeTransform _compositeTransform;  
    164.     #endregion  
    165.  
    166.     #region Template Part  
    167.     /// <summary>  
    168.     /// 矩形  
    169.     /// </summary>  
    170.     const string A_PARTNAME = "A";  
    171.     /// <summary>  
    172.     /// 矩形遮掩  
    173.     /// </summary>  
    174.     const string A_RECT_PARTNAME = "ARect";  
    175.     /// <summary>  
    176.     /// 矩形偏移  
    177.     /// </summary>  
    178.     const string A_TRANS_PARTNAME = "transA";  
    179.     const string A_PRESENTER_PARTNAME = "APresenter";  
    180.     const string B_PARTNAME = "B";  
    181.     const string B_RECT_PARTNAME = "BRect";  
    182.     const string B_TRANS_PARTNAME = "transB";  
    183.     const string B_PRESENTER_PARTNAME = "BPresenter";  
    184.     const string C_PARTNAME = "C";  
    185.     const string C_RECT_PARTNAME = "CRect";  
    186.     const string C_TRANS_PARTNAME = "transC";  
    187.     const string C_PRESENTER_PARTNAME = "CPresenter";  
    188.     const string D_PARTNAME = "D";  
    189.     const string D_RECT_PARTNAME = "DRect";  
    190.     const string D_TRANS_PARTNAME = "transD";  
    191.     const string D_PRESENTER_PARTNAME = "DPresenter";  
    192.     const string E_PARTNAME = "E";  
    193.     const string E_RECT_PARTNAME = "ERect";  
    194.     const string E_TRANS_PARTNAME = "transE";  
    195.     const string E_PRESENTER_PARTNAME = "EPresenter";  
    196.     const string F_PARTNAME = "F";  
    197.     const string F_RECT_PARTNAME = "FRect";  
    198.     const string F_TRANS_PARTNAME = "transF";  
    199.     const string F_PRESENTER_PARTNAME = "FPresenter";  
    200.     const string ST_SHADOW_SPLIT_OUTER_RIGHT_PARTNAME = "stShadowSplitOuterRight";  
    201.     const string ST_SHADOW_SPLIT_INNER_RIGHT_PARTNAME = "stShadowSplitInnerRight";  
    202.     const string ST_SHADOW_SPLIT_OUTER_LEFT_PARTNAME = "stShadowSplitOuterLeft";  
    203.     const string ST_SHADOW_SPLIT_INNER_LEFT_PARTNAME = "stShadowSplitInnerLeft";  
    204.     const string ST_SHADOW_MARGIN_LEFT_PARTNAME = "stShadowMarginLeft";  
    205.     const string ST_SHADOW_MARGIN_RIGHT_PARTNAME = "stShadowMarginRight";  
    206.     const string OUTER_LEFT_TRANS_PARTNAME = "outerLeftTrans";  
    207.     const string INNER_LEFT_TRANS_PARTNAME = "innerLeftTrans";  
    208.     const string OUTER_RIGHT_TRANS_PARTNAME = "outerRightTrans";  
    209.     const string INNER_RIGHT_TRANS_PARTNAME = "innerRightTrans";  
    210.     const string MARGIN_LEFT_TRANS_PARTNAME = "marginLeftTrans";  
    211.     const string MARGIN_RIGHT_TRANS_PARTNAME = "marginRightTrans";  
    212.     /// <summary>  
    213.     /// 书壳  
    214.     /// </summary>  
    215.     const string BOOK_CONTAINER_PARTNAME = "bookContainer";  
    216.     const string GRD_CONTENT_PARTNAME = "grdContent";  
    217.     #endregion  
    218.  
    219.     #region DependencyProperties  
    220.     #region DelayLoad  
    221.     public TimeSpan DelayLoad  
    222.     {  
    223.         get { return (TimeSpan)GetValue(DelayLoadProperty); }  
    224.         set { SetValue(DelayLoadProperty, value); }  
    225.     }  
    226.   
    227.     // Using a DependencyProperty as the backing store for DelayLoad.  This enables animation, styling, binding, etc...  
    228.     public static readonly DependencyProperty DelayLoadProperty =  
    229.         DependencyProperty.Register("DelayLoad"typeof(TimeSpan), typeof(FlipBookControl), new PropertyMetadata(TimeSpan.FromSeconds(0)));  
    230.     #endregion  
    231.  
    232.     #region BookBackgroundBrush  
    233.     public ImageBrush BookBackgroundBrush  
    234.     {  
    235.         get { return (ImageBrush)GetValue(BookBackgroundBrushProperty); }  
    236.         set { SetValue(BookBackgroundBrushProperty, value); }  
    237.     }  
    238.   
    239.     // Using a DependencyProperty as the backing store for BookBackgroundBrush.  This enables animation, styling, binding, etc...  
    240.     public static readonly DependencyProperty BookBackgroundBrushProperty =  
    241.         DependencyProperty.Register("BookBackgroundBrush"typeof(ImageBrush), typeof(FlipBookControl), new PropertyMetadata(null, OnBookBackgroundBrushChangedCallBack));  
    242.   
    243.     private static async void OnBookBackgroundBrushChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)  
    244.     {  
    245.   
    246.         var ctrl = (d as FlipBookControl);  
    247.         if (ctrl.isLoaded)  
    248.             await ctrl.GetCropBrush();  
    249.     }  
    250.     #endregion  
    251.  
    252.     #region Speed  
    253.     /// <summary>  
    254.     /// 动画速度 默认为30pixel  
    255.     /// </summary>  
    256.     public int Speed  
    257.     {  
    258.         get { return (int)GetValue(SpeedProperty); }  
    259.         set { SetValue(SpeedProperty, value); }  
    260.     }  
    261.   
    262.     // Using a DependencyProperty as the backing store for Speed.  This enables animation, styling, binding, etc...  
    263.     public static readonly DependencyProperty SpeedProperty =  
    264.         DependencyProperty.Register("Speed"typeof(int), typeof(FlipBookControl), new PropertyMetadata(30));  
    265.     #endregion  
    266.  
    267.     #region BookContainerSource  
    268.     public ImageSource BookContainerSource  
    269.     {  
    270.         get { return (ImageSource)GetValue(BookContainerSourceProperty); }  
    271.         set { SetValue(BookContainerSourceProperty, value); }  
    272.     }  
    273.   
    274.     // Using a DependencyProperty as the backing store for BookContainerSource.  This enables animation, styling, binding, etc...  
    275.     public static readonly DependencyProperty BookContainerSourceProperty =  
    276.         DependencyProperty.Register("BookContainerSource"typeof(ImageSource), typeof(FlipBookControl), new PropertyMetadata(null, OnBookContainerSourceChangedCallBack));  
    277.   
    278.     private static void OnBookContainerSourceChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)  
    279.     {  
    280.         var ctrl = (d as FlipBookControl);  
    281.         if (null != ctrl.BookContainerSource && ctrl.bookContainer != null && ctrl.isLoaded)  
    282.             ctrl.bookContainer.Source = ctrl.BookContainerSource;  
    283.     }  
    284.  
    285.     #endregion  
    286.  
    287.     #region PageIndex  
    288.     public int PageIndex  
    289.     {  
    290.         get { return (int)GetValue(PageIndexProperty); }  
    291.         set { SetValue(PageIndexProperty, value); }  
    292.     }  
    293.   
    294.     // Using a DependencyProperty as the backing store for PageIndex.  This enables animation, styling, binding, etc...  
    295.     public static readonly DependencyProperty PageIndexProperty =  
    296.         DependencyProperty.Register("PageIndex"typeof(int), typeof(FlipBookControl), new PropertyMetadata(0, OnPageIndexChangedCallBack));  
    297.   
    298.     private static void OnPageIndexChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)  
    299.     {  
    300.         var ctrl = (d as FlipBookControl);  
    301.         if (ctrl.isLoaded)  
    302.         {  
    303.             var isNext = Convert.ToInt32(e.NewValue) > Convert.ToInt32(e.OldValue);  
    304.             var presenters = ctrl.GetPresentersByPageIndex(isNext);  
    305.             if (null != presenters)  
    306.                 ctrl.LoadPageContentByPageIndex(Convert.ToInt32(e.NewValue), isNext, presenters[0], presenters[1]);  
    307.         }  
    308.     }  
    309.     #endregion  
    310.  
    311.     #region DisposeAction  
    312.     public Action<object> DisposeAction  
    313.     {  
    314.         get { return (Action<object>)GetValue(DisposeActionProperty); }  
    315.         set { SetValue(DisposeActionProperty, value); }  
    316.     }  
    317.   
    318.     // Using a DependencyProperty as the backing store for DisposeAction.  This enables animation, styling, binding, etc...  
    319.     public static readonly DependencyProperty DisposeActionProperty =  
    320.         DependencyProperty.Register("DisposeAction"typeof(Action<object>), typeof(FlipBookControl), new PropertyMetadata(null));  
    321.     #endregion  
    322.  
    323.     #region RestoreItemAction  
    324.     public Action<object> RestoreItemAction  
    325.     {  
    326.         get { return (Action<object>)GetValue(RestoreItemActionProperty); }  
    327.         set { SetValue(RestoreItemActionProperty, value); }  
    328.     }  
    329.   
    330.     // Using a DependencyProperty as the backing store for RestoreItemAction.  This enables animation, styling, binding, etc...  
    331.     public static readonly DependencyProperty RestoreItemActionProperty =  
    332.         DependencyProperty.Register("RestoreItemAction"typeof(Action<object>), typeof(FlipBookControl), new PropertyMetadata(null));  
    333.     #endregion  
    334.  
    335.     #region CanScale  
    336.     public bool CanScale  
    337.     {  
    338.         get { return (bool)GetValue(CanScaleProperty); }  
    339.         set { SetValue(CanScaleProperty, value); }  
    340.     }  
    341.   
    342.     // 能否进行放大缩小  
    343.     public static readonly DependencyProperty CanScaleProperty =  
    344.         DependencyProperty.Register("CanScale"typeof(bool), typeof(FlipBookControl), new PropertyMetadata(false));  
    345.     #endregion  
    346.     #endregion  
    347.  
    348.     #region Event  
    349.     /// <summary>  
    350.     /// 翻书结束事件  
    351.     /// </summary>  
    352.     private delegate void Fliped(object sender, FlipEventArgs args);  
    353.   
    354.     private event Fliped Fliping;  
    355.     /// <summary>  
    356.     /// 加载事件  
    357.     /// </summary>  
    358.     /// <param name="sender"></param>  
    359.     /// <param name="args"></param>  
    360.     public delegate void NeedLoadItems(object sender, FlipLoadArgs args);  
    361.   
    362.     public event NeedLoadItems NeedLoadingItem;  
    363.     #endregion  
    364.  
    365.     #region Constructor  
    366.     public FlipBookControl()  
    367.     {  
    368.         this.DefaultStyleKey = typeof(FlipBookControl);  
    369.         this.Loaded += FlipBookControlLoaded;  
    370.         this.Unloaded += FlipBookControlUnLoaded;  
    371.         CompositionTarget.Rendering += RenderAnimation;  
    372.         this.Fliping += FlipEnded;  
    373.     }  
    374.   
    375.     /// <summary>  
    376.     /// 初始化完毕开始载入数据  
    377.     /// </summary>  
    378.     /// <param name="sender"></param>  
    379.     /// <param name="e"></param>  
    380.     private async void FlipBookControlLoaded(object sender, RoutedEventArgs e)  
    381.     {  
    382.         grdContent.ManipulationMode =  
    383.           ManipulationModes.TranslateInertia |  
    384.           ManipulationModes.TranslateX |  
    385.           ManipulationModes.Scale |  
    386.           ManipulationModes.ScaleInertia |  
    387.           ManipulationModes.TranslateY;  
    388.         grdContent.ManipulationDelta += FlipManipulationDelta;  
    389.         grdContent.ManipulationCompleted += FlipManipulationCompleted;  
    390.         grdContent.ManipulationStarting += FlipManipulationStarting;  
    391.         grdContent.ManipulationInertiaStarting += FlipManipulationInertiaStarting;  
    392.         A.PointerPressed += PointerPressed;  
    393.         B.PointerPressed += PointerPressed;  
    394.         C.PointerPressed += PointerPressed;  
    395.         D.PointerPressed += PointerPressed;  
    396.         E.PointerPressed += PointerPressed;  
    397.         F.PointerPressed += PointerPressed;  
    398.         offsetWidth = A.ActualWidth;  
    399.         offsetHeight = A.ActualHeight;  
    400.         await GetCropBrush();  
    401.         bookContainer.Source = BookContainerSource;  
    402.         RefreshPageByStatus();  
    403.         InitPages();  
    404.         isLoaded = true;  
    405.     }  
    406.   
    407.     private void FlipBookControlUnLoaded(object sender, RoutedEventArgs e)  
    408.     {  
    409.         CompositionTarget.Rendering -= RenderAnimation;  
    410.         grdContent.ManipulationDelta -= FlipManipulationDelta;  
    411.         grdContent.ManipulationCompleted -= FlipManipulationCompleted;  
    412.         grdContent.ManipulationStarting -= FlipManipulationStarting;  
    413.         grdContent.ManipulationInertiaStarting -= FlipManipulationInertiaStarting;  
    414.         this.Fliping -= FlipEnded;  
    415.         A.PointerPressed -= PointerPressed;  
    416.         B.PointerPressed -= PointerPressed;  
    417.         C.PointerPressed -= PointerPressed;  
    418.         D.PointerPressed -= PointerPressed;  
    419.         E.PointerPressed -= PointerPressed;  
    420.         F.PointerPressed -= PointerPressed;  
    421.     }  
    422.   
    423.     public void InitPosition()  
    424.     {  
    425.         _compositeTransform = new CompositeTransform();  
    426.         _previousTransform = new MatrixTransform() { Matrix = Matrix.Identity };  
    427.         _transformGroup = new TransformGroup();  
    428.         _transformGroup.Children.Add(_previousTransform);  
    429.         _transformGroup.Children.Add(_compositeTransform);  
    430.         this.RenderTransform = _transformGroup;  
    431.     }  
    432.   
    433.     public async void InitPages()  
    434.     {  
    435.         if (!isInit && PageIndex == 0 && this.Items.Count > 0)  
    436.         {  
    437.             await Task.Delay(DelayLoad);  
    438.             List<object> needLoadItems = new List<object>();  
    439.             //第一次加载 载入4页  
    440.             CPresenter.DataContext = this.Items[0];  
    441.             needLoadItems.Add(Items[0]);  
    442.             if (this.Items.Count > 1)  
    443.             {  
    444.                 DPresenter.DataContext = this.Items[1];  
    445.                 needLoadItems.Add(Items[1]);  
    446.             }  
    447.             if (this.Items.Count > 2)  
    448.             {  
    449.                 EPresenter.DataContext = this.Items[2];  
    450.                 needLoadItems.Add(Items[2]);  
    451.             }  
    452.             if (this.Items.Count > 3)  
    453.             {  
    454.                 FPresenter.DataContext = this.Items[3];  
    455.                 needLoadItems.Add(Items[3]);  
    456.             }  
    457.             if (null != NeedLoadingItem)  
    458.                 NeedLoadingItem(thisnew FlipLoadArgs(needLoadItems, false));  
    459.             isInit = true;  
    460.         }  
    461.         else  
    462.         {  
    463.             Status = 0;  
    464.             this.PageIndex = 0;  
    465.             if (null != APresenter)  
    466.             {  
    467.                 APresenter.DataContext = null;  
    468.                 BPresenter.DataContext = null;  
    469.                 CPresenter.DataContext = null;  
    470.                 DPresenter.DataContext = null;  
    471.                 EPresenter.DataContext = null;  
    472.                 FPresenter.DataContext = null;  
    473.             }  
    474.         }  
    475.         InitPosition();  
    476.     }  
    477.     #endregion  
    478.  
    479.     #region EventMethod  
    480.     #region OnApplyTemplate  
    481.     protected override void OnApplyTemplate()  
    482.     {  
    483.         bookContainer = GetTemplateChild(BOOK_CONTAINER_PARTNAME) as Image;  
    484.         A = GetTemplateChild(A_PARTNAME) as Border;  
    485.         B = GetTemplateChild(B_PARTNAME) as Border;  
    486.         C = GetTemplateChild(C_PARTNAME) as Border;  
    487.         D = GetTemplateChild(D_PARTNAME) as Border;  
    488.         E = GetTemplateChild(E_PARTNAME) as Border;  
    489.         F = GetTemplateChild(F_PARTNAME) as Border;  
    490.         APresenter = GetTemplateChild(A_PRESENTER_PARTNAME) as ContentPresenter;  
    491.         BPresenter = GetTemplateChild(B_PRESENTER_PARTNAME) as ContentPresenter;  
    492.         CPresenter = GetTemplateChild(C_PRESENTER_PARTNAME) as ContentPresenter;  
    493.         DPresenter = GetTemplateChild(D_PRESENTER_PARTNAME) as ContentPresenter;  
    494.         EPresenter = GetTemplateChild(E_PRESENTER_PARTNAME) as ContentPresenter;  
    495.         FPresenter = GetTemplateChild(F_PRESENTER_PARTNAME) as ContentPresenter;  
    496.         ARect = GetTemplateChild(A_RECT_PARTNAME) as RectangleGeometry;  
    497.         BRect = GetTemplateChild(B_RECT_PARTNAME) as RectangleGeometry;  
    498.         CRect = GetTemplateChild(C_RECT_PARTNAME) as RectangleGeometry;  
    499.         DRect = GetTemplateChild(D_RECT_PARTNAME) as RectangleGeometry;  
    500.         ERect = GetTemplateChild(E_RECT_PARTNAME) as RectangleGeometry;  
    501.         FRect = GetTemplateChild(F_RECT_PARTNAME) as RectangleGeometry;  
    502.         transA = GetTemplateChild(A_TRANS_PARTNAME) as CompositeTransform;  
    503.         transB = GetTemplateChild(B_TRANS_PARTNAME) as CompositeTransform;  
    504.         transC = GetTemplateChild(C_TRANS_PARTNAME) as CompositeTransform;  
    505.         transD = GetTemplateChild(D_TRANS_PARTNAME) as CompositeTransform;  
    506.         transE = GetTemplateChild(E_TRANS_PARTNAME) as CompositeTransform;  
    507.         transF = GetTemplateChild(F_TRANS_PARTNAME) as CompositeTransform;  
    508.         grdContent = GetTemplateChild(GRD_CONTENT_PARTNAME) as Grid;  
    509.         innerLeftTrans = GetTemplateChild(INNER_LEFT_TRANS_PARTNAME) as CompositeTransform;  
    510.         outerLeftTrans = GetTemplateChild(OUTER_LEFT_TRANS_PARTNAME) as CompositeTransform;  
    511.         innerRightTrans = GetTemplateChild(INNER_RIGHT_TRANS_PARTNAME) as CompositeTransform;  
    512.         outerRightTrans = GetTemplateChild(OUTER_RIGHT_TRANS_PARTNAME) as CompositeTransform;  
    513.         marginLeftTrans = GetTemplateChild(MARGIN_LEFT_TRANS_PARTNAME) as CompositeTransform;  
    514.         marginRightTrans = GetTemplateChild(MARGIN_RIGHT_TRANS_PARTNAME) as CompositeTransform;  
    515.         stShadowSplitInnerLeft = GetTemplateChild(ST_SHADOW_SPLIT_INNER_LEFT_PARTNAME) as StackPanel;  
    516.         stShadowSplitOuterLeft = GetTemplateChild(ST_SHADOW_SPLIT_OUTER_LEFT_PARTNAME) as StackPanel;  
    517.         stShadowSplitInnerRight = GetTemplateChild(ST_SHADOW_SPLIT_INNER_RIGHT_PARTNAME) as StackPanel;  
    518.         stShadowSplitOuterRight = GetTemplateChild(ST_SHADOW_SPLIT_OUTER_RIGHT_PARTNAME) as StackPanel;  
    519.         stShadowMarginLeft = GetTemplateChild(ST_SHADOW_MARGIN_LEFT_PARTNAME) as StackPanel;  
    520.         stShadowMarginRight = GetTemplateChild(ST_SHADOW_MARGIN_RIGHT_PARTNAME) as StackPanel;  
    521.         base.OnApplyTemplate();  
    522.     }  
    523.     #endregion  
    524.  
    525.     #region PointerPressed  
    526.     /// <summary>  
    527.     /// 确定翻页方向  
    528.     /// </summary>  
    529.     /// <param name="sender"></param>  
    530.     /// <param name="e"></param>  
    531.     private void PointerPressed(object sender, PointerRoutedEventArgs e)  
    532.     {  
    533.         if (!isManipulating)  
    534.         {  
    535.             if (sender.Equals(leftPage))  
    536.                 isNext = false;  
    537.             else if (sender.Equals(rightPage))  
    538.                 isNext = true;  
    539.             else  
    540.                 RefreshPageByStatus();  
    541.             Debug.WriteLine("按下:" + isNext);  
    542.             Debug.WriteLine("点击的壳:" + (sender as Border).Name + " 左页壳:" + (sender as Border).Name);  
    543.         }  
    544.     }  
    545.     #endregion  
    546.  
    547.     #region OnPointerReleased  
    548.     protected override void OnPointerReleased(PointerRoutedEventArgs e)  
    549.     {  
    550.         base.OnPointerReleased(e);  
    551.     }  
    552.     #endregion  
    553.  
    554.     #region FlipEnded  
    555.     /// <summary>  
    556.     /// 翻页完毕  
    557.     /// </summary>  
    558.     /// <param name="sender"></param>  
    559.     /// <param name="args"></param>  
    560.     private async void FlipEnded(object sender, FlipEventArgs args)  
    561.     {  
    562.         Debug.WriteLine("翻页完毕:" + args.isNext);  
    563.         if (args.isNext) PageIndex += 2;  
    564.         else PageIndex -= 2;  
    565.         await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>  
    566.         RefreshPageByStatus());  
    567.     }  
    568.     #endregion  
    569.  
    570.     #region Manipulation  多点触控操作翻书特效  
    571.     #region FlipManipulationStarting  
    572.     private void FlipManipulationStarting(object sender, ManipulationStartingRoutedEventArgs e)  
    573.     {  
    574.         isManipulating = true;  
    575.         e.Handled = true;  
    576.         if (isNext)  
    577.         {  
    578.             if (PageIndex >= this.Items.Count - 2)  
    579.             {  
    580.                 isFlip = false;  
    581.                 isManipulating = false;  
    582.             }  
    583.         }  
    584.         else  
    585.         {  
    586.             if (this.PageIndex == 0)  
    587.             {  
    588.                 isFlip = false;  
    589.                 isManipulating = false;  
    590.             }  
    591.         }  
    592.     }  
    593.     #endregion  
    594.  
    595.     #region FlipManipulationInertiaStarting  
    596.     private void FlipManipulationInertiaStarting(object sender, ManipulationInertiaStartingRoutedEventArgs e)  
    597.     {  
    598.         e.TranslationBehavior.DesiredDeceleration = 5 * 96.0 / (1000.0 * 1000.0);  
    599.         e.ExpansionBehavior.DesiredDeceleration = 100 * 96 / 1000.0 * 1000.0;  
    600.     }  
    601.     #endregion  
    602.  
    603.     #region FlipManipulationCompleted  
    604.     private async void FlipManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)  
    605.     {  
    606.         isManipulating = false;  
    607.         if (isFlip)  
    608.         {  
    609.             IsHitVisible(false);  
    610.             var leftTopOffset = leftTopPage.Clip.Rect.X;  
    611.             var rightTopOffset = rightTopPage.Clip.Rect.X;  
    612.             await Task.Run(() =>  
    613.             {  
    614.                 if (isNext)  
    615.                 {  
    616.                     if (lastDeltaOffset < 0)  
    617.                     {  
    618.                         Status = Status < 2 ? Status + 1 : 0;  
    619.                         turnRight = true;  
    620.                     }  
    621.                     else if (rightTopOffset != 0.0)  
    622.                         rightRestore = true;  
    623.                     else IsHitVisible(true);  
    624.                     Debug.WriteLine("下一页:" + turnRight);  
    625.                 }  
    626.                 else  
    627.                 {  
    628.                     if (lastDeltaOffset > 0)  
    629.                     {  
    630.                         Status = Status > 0 ? Status - 1 : 2;  
    631.                         turnLeft = true;  
    632.                     }  
    633.                     else if (leftTopOffset != 0.0)  
    634.                         leftRestore = true;  
    635.                     else IsHitVisible(true);  
    636.                     Debug.WriteLine("上一页" + turnLeft);  
    637.                 }  
    638.             });  
    639.   
    640.             Debug.WriteLine("翻页状态:" + Status);  
    641.         }  
    642.         isFlip = true;  
    643.         CanScale = false;  
    644.     }  
    645.     #endregion  
    646.  
    647.     #region FlipManipulationDelta  
    648.     private void FlipManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)  
    649.     {  
    650.         var scale = e.Delta.Scale;  
    651.         var translateX = e.Delta.Translation.X;  
    652.         var translateY = e.Delta.Translation.Y;  
    653.         var nTtranX = nextTrans.TranslateX;  
    654.         var nTtranY = nextTrans.TranslateY;  
    655.         var ctranlateX = e.Cumulative.Translation.X;  
    656.         var ctranlateY = e.Cumulative.Translation.Y;  
    657.         CanScale = Task.Run(() =>  
    658.         {  
    659.             if (scale != 1.0 || (Math.Abs(ctranlateX * 1.15) < Math.Abs(ctranlateY))) return true;  
    660.             else return false;  
    661.         }).Result;  
    662.         if (isManipulating && !CanScale)  
    663.         {  
    664.             if (isNext)  
    665.             {  
    666.                 #region 下一页  
    667.                 var rightTopNect = rightTopPage.Clip.Rect;  
    668.                 var nextRect = nextPage.Clip.Rect;  
    669.                 var nextTransOffset = nTtranX + translateX * 2;  
    670.   
    671.                 SetShadowOperacity(Math.Abs(nextTransOffset), offsetWidth, false);  
    672.                 var nextRectXOffset = nextRect.X - e.Delta.Translation.X;  
    673.                 lastDeltaOffset = e.Delta.Translation.X;  
    674.                 if (nextRectXOffset < 0 && nextRectXOffset > -offsetWidth)  
    675.                 {  
    676.                     outerRightTrans.TranslateX += e.Delta.Translation.X;  
    677.                     innerRightTrans.TranslateX += e.Delta.Translation.X;  
    678.                     marginRightTrans.TranslateX += e.Delta.Translation.X * 2;  
    679.   
    680.                     nextTrans.TranslateX = nextTransOffset;  
    681.                     if (nextRectXOffset < 0)  
    682.                         nextRect.X = nextRectXOffset;  
    683.                     rightTopNect.X += e.Delta.Translation.X;  
    684.                     nextPage.Clip.Rect = nextRect;  
    685.                     rightTopPage.Clip.Rect = rightTopNect;  
    686.                 }  
    687.                 else  
    688.                 {  
    689.                     e.Complete();  
    690.                     if (nextTransOffset < 0)  
    691.                     {  
    692.                         nextTrans.TranslateX = -offsetWidth;  
    693.                         nextRect.X = 0;  
    694.                         rightTopNect.X = 0;  
    695.                         nextPage.Clip.Rect = nextRect;  
    696.                         rightTopPage.Clip.Rect = rightTopNect;  
    697.                     }  
    698.                     else  
    699.                     {  
    700.                         nextTrans.TranslateX = offsetWidth;  
    701.                         nextRect.X = -offsetWidth;  
    702.                         rightTopNect.X = offsetWidth;  
    703.                         nextPage.Clip.Rect = nextRect;  
    704.                         rightTopPage.Clip.Rect = rightTopNect;  
    705.                     }  
    706.                 }  
    707.                 #endregion  
    708.             }  
    709.             else  
    710.             {  
    711.                 #region 上一页  
    712.                 var leftTopNect = leftTopPage.Clip.Rect;  
    713.                 var prevRect = prevPage.Clip.Rect;  
    714.                 var prevTransOffset = prevTrans.TranslateX + e.Delta.Translation.X * 2;  
    715.                 var prevRectXOffset = prevRect.X - e.Delta.Translation.X;  
    716.                 SetShadowOperacity(Math.Abs(prevTransOffset), offsetWidth, true);  
    717.                 lastDeltaOffset = e.Delta.Translation.X;  
    718.                 if (prevRectXOffset > 0 && prevRectXOffset < offsetWidth)  
    719.                 {  
    720.                     innerLeftTrans.TranslateX += translateX;  
    721.                     outerLeftTrans.TranslateX += translateX;  
    722.                     marginLeftTrans.TranslateX += translateX * 2;  
    723.   
    724.                     prevTrans.TranslateX = prevTransOffset;  
    725.                     if (prevRectXOffset > 0)  
    726.                         prevRect.X = prevRectXOffset;  
    727.                     leftTopNect.X += e.Delta.Translation.X;  
    728.                     prevPage.Clip.Rect = prevRect;  
    729.                     leftTopPage.Clip.Rect = leftTopNect;  
    730.                 }  
    731.                 else  
    732.                 {  
    733.                     e.Complete();  
    734.                     if (prevTransOffset < 0)  
    735.                     {  
    736.                         prevTrans.TranslateX = -offsetWidth;  
    737.                         prevRect.X = offsetWidth;  
    738.                         leftTopNect.X = -offsetWidth;  
    739.                         prevPage.Clip.Rect = prevRect;  
    740.                         leftTopPage.Clip.Rect = leftTopNect;  
    741.   
    742.                     }  
    743.                     else  
    744.                     {  
    745.                         prevTrans.TranslateX = offsetWidth;  
    746.                         prevRect.X = 0;  
    747.                         leftTopNect.X = 0;  
    748.                         prevPage.Clip.Rect = prevRect;  
    749.                         leftTopPage.Clip.Rect = leftTopNect;  
    750.                     }  
    751.                 }  
    752.                 #endregion  
    753.             }  
    754.         }  
    755.         if (CanScale)  
    756.         {  
    757.             _previousTransform.Matrix = _transformGroup.Value;  
    758.             Point center = _previousTransform.TransformPoint(new Point(e.Position.X, e.Position.Y));  
    759.             _compositeTransform.CenterX = center.X;  
    760.             _compositeTransform.CenterY = center.Y;  
    761.             _compositeTransform.ScaleX = e.Delta.Scale;  
    762.             _compositeTransform.ScaleY = e.Delta.Scale;  
    763.             _compositeTransform.TranslateX = e.Delta.Translation.X;  
    764.             _compositeTransform.TranslateY = e.Delta.Translation.Y;  
    765.         }  
    766.     }  
    767.     #endregion  
    768.     #endregion  
    769.  
    770.     #region RenderAnimation 绘制翻页动画  
    771.     private void RenderAnimation(object sender, object e)  
    772.     {  
    773.         if (turnLeft)  
    774.         {  
    775.             rightRestore = false;  
    776.             turnRight = false;  
    777.             var prevRect = prevPage.Clip.Rect;  
    778.             var leftTopRect = leftTopPage.Clip.Rect;  
    779.             var prevOffset = prevRect.X - Speed / 2;  
    780.             if (prevOffset > 0)  
    781.             {  
    782.                 prevRect.X = prevOffset;  
    783.                 prevTrans.TranslateX += Speed;  
    784.                 leftTopRect.X += Speed / 2;  
    785.                 innerLeftTrans.TranslateX += Speed / 2;  
    786.                 outerLeftTrans.TranslateX += Speed / 2;  
    787.                 marginLeftTrans.TranslateX += Speed;  
    788.                 SetShadowOperacity(Math.Abs(prevTrans.TranslateX), offsetWidth, true);  
    789.             }  
    790.             else  
    791.             {  
    792.                 prevRect.X = 0;  
    793.                 leftTopRect.X = 0;  
    794.                 turnLeft = false;  
    795.                 prevTrans.TranslateX = offsetWidth;  
    796.                 Fliping(sender, new FlipEventArgs(false));  
    797.   
    798.             }  
    799.             prevPage.Clip.Rect = prevRect;  
    800.             leftTopPage.Clip.Rect = leftTopRect;  
    801.             IsHitVisible(true);  
    802.         }  
    803.         else if (leftRestore)  
    804.         {  
    805.             turnLeft = false;  
    806.             turnRight = false;  
    807.             rightRestore = false;  
    808.             var prevRect = prevPage.Clip.Rect;  
    809.             var leftTopRect = leftTopPage.Clip.Rect;  
    810.             var prevOffset = prevRect.X + Speed / 2;  
    811.             if (prevOffset < offsetWidth)  
    812.             {  
    813.                 prevRect.X = prevOffset;  
    814.                 prevTrans.TranslateX -= Speed;  
    815.                 leftTopRect.X -= Speed / 2;  
    816.                 innerLeftTrans.TranslateX -= Speed / 2;  
    817.                 outerLeftTrans.TranslateX -= Speed / 2;  
    818.                 marginLeftTrans.TranslateX -= Speed;  
    819.                 SetShadowOperacity(Math.Abs(prevTrans.TranslateX), offsetWidth, true);  
    820.             }  
    821.             else  
    822.             {  
    823.                 prevRect.X = offsetWidth;  
    824.                 leftTopRect.X = -offsetWidth;  
    825.                 prevTrans.TranslateX = -offsetWidth;  
    826.                 innerLeftTrans.TranslateX = 0;  
    827.                 outerLeftTrans.TranslateX = 0;  
    828.                 marginLeftTrans.TranslateX = 0;  
    829.                 leftRestore = false;  
    830.   
    831.             }  
    832.             prevPage.Clip.Rect = prevRect;  
    833.             leftTopPage.Clip.Rect = leftTopRect;  
    834.             IsHitVisible(true);  
    835.         }  
    836.         else if (turnRight)  
    837.         {  
    838.   
    839.             rightRestore = false;  
    840.             turnLeft = false;  
    841.             var nextRect = nextPage.Clip.Rect;  
    842.             var rightTopRect = rightTopPage.Clip.Rect;  
    843.             var nextOffset = nextRect.X + Speed / 2;  
    844.             if (nextOffset < 0)  
    845.             {  
    846.                 nextRect.X = nextOffset;  
    847.                 nextTrans.TranslateX -= Speed;  
    848.                 rightTopRect.X -= Speed / 2;  
    849.                 innerRightTrans.TranslateX -= Speed / 2;  
    850.                 outerRightTrans.TranslateX -= Speed / 2;  
    851.                 marginRightTrans.TranslateX -= Speed;  
    852.                 SetShadowOperacity(Math.Abs(nextTrans.TranslateX), offsetWidth, false);  
    853.             }  
    854.             else  
    855.             {  
    856.                 nextRect.X = 0;  
    857.                 nextTrans.TranslateX = -offsetWidth;  
    858.                 turnRight = false;  
    859.                 rightTopRect.X = 0;  
    860.                 Fliping(sender, new FlipEventArgs(true));  
    861.             }  
    862.             nextPage.Clip.Rect = nextRect;  
    863.             rightTopPage.Clip.Rect = rightTopRect;  
    864.             IsHitVisible(true);  
    865.         }  
    866.         else if (rightRestore)  
    867.         {  
    868.   
    869.             turnRight = false;  
    870.             turnLeft = false;  
    871.             leftRestore = false;  
    872.             var nextRect = nextPage.Clip.Rect;  
    873.             var rightTopRect = rightTopPage.Clip.Rect;  
    874.             var nextOffset = nextRect.X - Speed / 2;  
    875.             if (nextRect.X - Speed / 2 > -offsetWidth)  
    876.             {  
    877.                 nextRect.X = nextOffset;  
    878.                 nextTrans.TranslateX += Speed;  
    879.                 rightTopRect.X += Speed / 2;  
    880.                 innerRightTrans.TranslateX += Speed / 2;  
    881.                 outerRightTrans.TranslateX += Speed / 2;  
    882.                 marginRightTrans.TranslateX += Speed;  
    883.                 SetShadowOperacity(Math.Abs(nextTrans.TranslateX), offsetWidth, false);  
    884.             }  
    885.             else  
    886.             {  
    887.                 nextRect.X = -offsetWidth;  
    888.                 rightTopRect.X = offsetWidth;  
    889.                 nextTrans.TranslateX = offsetWidth;  
    890.                 innerRightTrans.TranslateX = 0;  
    891.                 outerRightTrans.TranslateX = 0;  
    892.                 marginRightTrans.TranslateX = 0;  
    893.                 rightRestore = false;  
    894.             }  
    895.             rightTopPage.Clip.Rect = rightTopRect;  
    896.             nextPage.Clip.Rect = nextRect;  
    897.             IsHitVisible(true);  
    898.         }  
    899.     }  
    900.     #endregion  
    901.     #endregion  
    902.  
    903.     #region Method  
    904.     #region LoadPageContentByPageIndex  
    905.     private void LoadPageContentByPageIndex(int PageIndex, bool isNextOrPrev, ContentPresenter firstPresenter, ContentPresenter secondPresenter)  
    906.     {  
    907.         List<object> needLoadItems = new List<object>();  
    908.         if (isNextOrPrev)  
    909.         {  
    910.             //加载下一页模板  
    911.             if (PageIndex + 2 < this.Items.Count)  
    912.             {  
    913.                 firstPresenter.Content = null;  
    914.                 firstPresenter.DataContext = null;  
    915.                 object item = null;  
    916.                 if (this.Items.Count > PageIndex + 2)  
    917.                 {  
    918.                     item = this.Items[PageIndex + 2];  
    919.                     needLoadItems.Add(item);  
    920.                     firstPresenter.DataContext = item;  
    921.                 }  
    922.             }  
    923.             else firstPresenter.DataContext = null;  
    924.             if (PageIndex + 3 < this.Items.Count)  
    925.             {  
    926.                 object item = null;  
    927.                 secondPresenter.Content = null;  
    928.                 secondPresenter.DataContext = null;  
    929.                 if (this.Items.Count > PageIndex + 3)  
    930.                 {  
    931.                     item = this.Items[PageIndex + 3];  
    932.                     needLoadItems.Add(item);  
    933.                     secondPresenter.DataContext = item;  
    934.                 }  
    935.             }  
    936.             else secondPresenter.DataContext = null;  
    937.             if (null != NeedLoadingItem)  
    938.                 NeedLoadingItem(thisnew FlipLoadArgs(needLoadItems, true));  
    939.             RecycleData(true, needLoadItems);  
    940.         }  
    941.         else  
    942.         {  
    943.             if (PageIndex - 2 >= 0 && Items.Count > PageIndex - 2)  
    944.             {  
    945.                 needLoadItems.Add(this.Items[PageIndex - 2]);  
    946.                 secondPresenter.Content = null;  
    947.                 secondPresenter.DataContext = null;  
    948.                 secondPresenter.DataContext = this.Items[PageIndex - 2];  
    949.             }  
    950.             if (PageIndex - 1 >= 0 && Items.Count > PageIndex - 1)  
    951.             {  
    952.                 firstPresenter.Content = null;  
    953.                 firstPresenter.DataContext = null;  
    954.                 firstPresenter.DataContext = this.Items[PageIndex - 1];  
    955.                 needLoadItems.Add(this.Items[PageIndex - 1]);  
    956.             }  
    957.             //加载上一页模板  
    958.             if (null != NeedLoadingItem)  
    959.                 NeedLoadingItem(thisnew FlipLoadArgs(needLoadItems, false));  
    960.             RecycleData(false, needLoadItems);  
    961.         }  
    962.     }  
    963.     #endregion  
    964.  
    965.     #region RecycleData  
    966.     private async void RecycleData(bool isNext, List<object> needItems)  
    967.     {  
    968.         await Task.Run(async () =>  
    969.         {  
    970.             foreach (var o in needItems)  
    971.             {  
    972.                 await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>  
    973.                 {  
    974.                     if (null != this.RestoreItemAction)  
    975.                         this.RestoreItemAction.Invoke(o);  
    976.                 });  
    977.             }  
    978.             if (isNext)  
    979.             {  
    980.                 var index = -1;  
    981.                 try  
    982.                 {  
    983.                     index = this.Items.IndexOf(needItems[0]);  
    984.   
    985.                 }  
    986.                 catch  
    987.                 {  
    988.                     index = -1;  
    989.                 }  
    990.                 if (index != -1 && index - 8 > 0)  
    991.                 {  
    992.                     for (int i = index - 8; i < index - 6; i++)  
    993.                         await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>  
    994.                         {  
    995.                             if (null != this.DisposeAction)  
    996.                                 DisposeAction.Invoke(this.Items[i]);  
    997.                         });  
    998.                 }  
    999.             }  
    1000.             else  
    1001.             {  
    1002.                 var index = -1;  
    1003.                 try  
    1004.                 {  
    1005.                     index = this.Items.IndexOf(needItems.Last());  
    1006.   
    1007.                 }  
    1008.                 catch (Exception ex)  
    1009.                 {  
    1010.                     index = -1;  
    1011.                 }  
    1012.                 if (index != -1 && this.Items.Count > index + 7)  
    1013.                 {  
    1014.                     for (int i = index + 5; i < index + 7; i++)  
    1015.                         await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>  
    1016.                         {  
    1017.                             if (null != this.DisposeAction)  
    1018.                                 DisposeAction.Invoke(this.Items[i]);  
    1019.                         });  
    1020.                 }  
    1021.             }  
    1022.         });  
    1023.     }  
    1024.     #endregion  
    1025.  
    1026.     #region OnItemsChanged  
    1027.     /// <summary>  
    1028.     /// 刷新数据   
    1029.     /// </summary>  
    1030.     /// <param name="e"></param>  
    1031.     protected override void OnItemsChanged(object e)  
    1032.     {  
    1033.         isInit = false;  
    1034.         InitPages();  
    1035.         base.OnItemsChanged(e);  
    1036.     }  
    1037.     #endregion  
    1038.  
    1039.     #region GetPresentersByPageIndex  
    1040.     private List<ContentPresenter> GetPresentersByPageIndex(bool isNext)  
    1041.     {  
    1042.         List<ContentPresenter> presenters = new List<ContentPresenter>();  
    1043.         if (isNext)  
    1044.         {  
    1045.             presenters.Add(leftTopPage.Child as ContentPresenter);  
    1046.             presenters.Add(prevPage.Child as ContentPresenter);  
    1047.         }  
    1048.         else  
    1049.         {  
    1050.             presenters.Add(rightTopPage.Child as ContentPresenter);  
    1051.             presenters.Add(nextPage.Child as ContentPresenter);  
    1052.         }  
    1053.         Debug.WriteLine("presenter0Name:" + presenters[0].Name);  
    1054.         Debug.WriteLine("presenter1Name:" + presenters[1].Name);  
    1055.         return presenters;  
    1056.     }  
    1057.     #endregion  
    1058.  
    1059.     #region Crop  
    1060.     /// <summary>  
    1061.     /// 图形切割  
    1062.     /// </summary>  
    1063.     /// <param name="source"></param>  
    1064.     /// <param name="x1"></param>  
    1065.     /// <param name="y1"></param>  
    1066.     /// <param name="x2"></param>  
    1067.     /// <param name="y2"></param>  
    1068.     /// <returns></returns>  
    1069.     public WriteableBitmap Crop(WriteableBitmap source, int x1, int y1, int x2, int y2)  
    1070.     {  
    1071.         if (x1 >= x2 ||  
    1072.             y1 >= y2 ||  
    1073.             x1 < 0 ||  
    1074.             y1 < 0 ||  
    1075.             x2 < 0 ||  
    1076.             y2 < 0 ||  
    1077.             x1 > source.PixelWidth ||  
    1078.             y1 > source.PixelHeight ||  
    1079.             x2 > source.PixelWidth ||  
    1080.             y2 > source.PixelHeight)  
    1081.         {  
    1082.             throw new ArgumentException();  
    1083.         }  
    1084.   
    1085.         //var buffer = source.PixelBuffer.GetPixels();  
    1086.         var cw = x2 - x1;  
    1087.         var ch = y2 - y1;  
    1088.         var target = new WriteableBitmap(cw, ch);  
    1089.   
    1090.         var croppedBytes =  
    1091.             new byte[4 * cw * ch];  
    1092.         var inputStream = source.PixelBuffer.AsStream();  
    1093.         inputStream.Seek(4 * (source.PixelWidth * y1 + x1), SeekOrigin.Current);  
    1094.         for (int i = 0; i < ch; i++)  
    1095.         {  
    1096.             inputStream.Read(croppedBytes, 4 * cw * i, 4 * cw);  
    1097.             inputStream.Seek(4 * (source.PixelWidth - cw), SeekOrigin.Current);  
    1098.         }  
    1099.   
    1100.         var outputStream = target.PixelBuffer.AsStream();  
    1101.         outputStream.Seek(0, SeekOrigin.Begin);  
    1102.         outputStream.Write(croppedBytes, 0, croppedBytes.Length);  
    1103.         target.Invalidate();  
    1104.   
    1105.         return target;  
    1106.     }  
    1107.     #endregion  
    1108.  
    1109.     #region IsHitVisible  
    1110.     /// <summary>  
    1111.     /// 禁止点击  
    1112.     /// </summary>  
    1113.     /// <param name="o"></param>  
    1114.     private async void IsHitVisible(bool o)  
    1115.     {  
    1116.         await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>  
    1117.         {  
    1118.             this.grdContent.IsHitTestVisible = o;  
    1119.             this.leftPage.IsHitTestVisible = o;  
    1120.             this.rightPage.IsHitTestVisible = o;  
    1121.             this.nextPage.IsHitTestVisible = o;  
    1122.             this.prevPage.IsHitTestVisible = o;  
    1123.             this.leftTopPage.IsHitTestVisible = o;  
    1124.             this.rightTopPage.IsHitTestVisible = o;  
    1125.         });  
    1126.     }  
    1127.     #endregion  
    1128.  
    1129.     #region RefreshPageByStatus  
    1130.     /// <summary>  
    1131.     /// 翻页成功后刷新控件状态  
    1132.     /// </summary>  
    1133.     private void RefreshPageByStatus()  
    1134.     {  
    1135.   
    1136.         switch (Status)  
    1137.         {  
    1138.             case 0:  
    1139.                 Canvas.SetZIndex(A, 2);  
    1140.                 Canvas.SetZIndex(B, 2);  
    1141.                 Canvas.SetZIndex(C, 0);  
    1142.                 Canvas.SetZIndex(D, 0);  
    1143.                 Canvas.SetZIndex(E, 2);  
    1144.                 Canvas.SetZIndex(F, 2);  
    1145.                 Grid.SetColumn(A, 1);  
    1146.                 Grid.SetColumn(B, 1);  
    1147.                 Grid.SetColumn(C, 1);  
    1148.                 Grid.SetColumn(D, 2);  
    1149.                 Grid.SetColumn(E, 2);  
    1150.                 Grid.SetColumn(F, 2);  
    1151.                 transA.TranslateX = 0;  
    1152.                 transB.TranslateX = -offsetWidth;  
    1153.                 transC.TranslateX = 0;  
    1154.                 transD.TranslateX = 0;  
    1155.                 transE.TranslateX = offsetWidth;  
    1156.                 transF.TranslateX = 0;  
    1157.                 ARect.Rect = new Rect(-this.A.ActualWidth, 0, this.A.ActualWidth, this.A.ActualHeight);  
    1158.                 CRect.Rect = new Rect(0, 0, this.C.ActualWidth, this.C.ActualHeight);  
    1159.                 DRect.Rect = new Rect(0, 0, this.D.ActualWidth, this.D.ActualHeight);  
    1160.                 FRect.Rect = new Rect(this.F.ActualWidth, 0, this.F.ActualWidth, this.F.ActualHeight);  
    1161.                 BRect.Rect = new Rect(this.B.ActualWidth, 0, this.B.ActualWidth, this.B.ActualHeight);  
    1162.                 ERect.Rect = new Rect(-this.E.ActualWidth, 0, this.E.ActualWidth, this.E.ActualHeight);  
    1163.                 nextPage = E;  
    1164.                 prevPage = B;  
    1165.                 leftPage = C;  
    1166.                 rightPage = D;  
    1167.                 leftTopPage = A;  
    1168.                 rightTopPage = F;  
    1169.                 nextTrans = transE;  
    1170.                 prevTrans = transB;  
    1171.                 //A.PointerPressed -= this.PointerPressed;  
    1172.                 //B.PointerPressed -= this.PointerPressed;  
    1173.                 //C.PointerPressed += this.PointerPressed;  
    1174.                 //D.PointerPressed += this.PointerPressed;  
    1175.                 break;  
    1176.             case 1:  
    1177.                 Canvas.SetZIndex(A, 2);  
    1178.                 Canvas.SetZIndex(B, 2);  
    1179.                 Canvas.SetZIndex(C, 2);  
    1180.                 Canvas.SetZIndex(D, 2);  
    1181.                 Canvas.SetZIndex(E, 0);  
    1182.                 Canvas.SetZIndex(F, 0);  
    1183.                 Grid.SetColumn(A, 2);  
    1184.                 Grid.SetColumn(B, 2);  
    1185.                 Grid.SetColumn(C, 1);  
    1186.                 Grid.SetColumn(D, 1);  
    1187.                 Grid.SetColumn(E, 1);  
    1188.                 Grid.SetColumn(F, 2);  
    1189.                 transA.TranslateX = offsetWidth;  
    1190.                 transB.TranslateX = 0;  
    1191.                 transC.TranslateX = 0;  
    1192.                 transD.TranslateX = -offsetWidth;  
    1193.                 transE.TranslateX = 0;  
    1194.                 transF.TranslateX = 0;  
    1195.                 ARect.Rect = new Rect(-this.A.ActualWidth, 0, this.A.ActualWidth, this.A.ActualHeight);  
    1196.                 CRect.Rect = new Rect(-this.C.ActualWidth, 0, this.C.ActualWidth, this.C.ActualHeight);  
    1197.                 DRect.Rect = new Rect(this.D.ActualWidth, 0, this.D.ActualWidth, this.D.ActualHeight);  
    1198.                 FRect.Rect = new Rect(0, 0, this.F.ActualWidth, this.F.ActualHeight);  
    1199.                 BRect.Rect = new Rect(this.B.ActualWidth, 0, this.B.ActualWidth, this.B.ActualHeight);  
    1200.                 ERect.Rect = new Rect(0, 0, this.E.ActualWidth, this.E.ActualHeight);  
    1201.                 nextPage = A;  
    1202.                 prevPage = D;  
    1203.                 leftPage = E;  
    1204.                 rightPage = F;  
    1205.                 leftTopPage = C;  
    1206.                 rightTopPage = B;  
    1207.                 nextTrans = transA;  
    1208.                 prevTrans = transD;  
    1209.                 //C.PointerPressed -= this.PointerPressed;  
    1210.                 //D.PointerPressed -= this.PointerPressed;  
    1211.                 //E.PointerPressed += this.PointerPressed;  
    1212.                 //F.PointerPressed += this.PointerPressed;  
    1213.                 break;  
    1214.             case 2:  
    1215.                 Canvas.SetZIndex(A, 0);  
    1216.                 Canvas.SetZIndex(B, 0);  
    1217.                 Canvas.SetZIndex(C, 2);  
    1218.                 Canvas.SetZIndex(D, 2);  
    1219.                 Canvas.SetZIndex(E, 2);  
    1220.                 Canvas.SetZIndex(F, 2);  
    1221.                 Grid.SetColumn(A, 1);  
    1222.                 Grid.SetColumn(B, 2);  
    1223.                 Grid.SetColumn(C, 2);  
    1224.                 Grid.SetColumn(D, 2);  
    1225.                 Grid.SetColumn(E, 1);  
    1226.                 Grid.SetColumn(F, 1);  
    1227.                 transA.TranslateX = 0;  
    1228.                 transB.TranslateX = 0;  
    1229.                 transC.TranslateX = offsetWidth;  
    1230.                 transD.TranslateX = 0;  
    1231.                 transE.TranslateX = 0;  
    1232.                 transF.TranslateX = -offsetWidth;  
    1233.                 ARect.Rect = new Rect(0, 0, this.A.ActualWidth, this.A.ActualHeight);  
    1234.                 CRect.Rect = new Rect(-this.C.ActualWidth, 0, this.C.ActualWidth, this.C.ActualHeight);  
    1235.                 DRect.Rect = new Rect(this.D.ActualWidth, 0, this.D.ActualWidth, this.D.ActualHeight);  
    1236.                 FRect.Rect = new Rect(this.F.ActualWidth, 0, this.F.ActualWidth, this.F.ActualHeight);  
    1237.                 BRect.Rect = new Rect(0, 0, this.B.ActualWidth, this.B.ActualHeight);  
    1238.                 ERect.Rect = new Rect(-this.E.ActualWidth, 0, this.E.ActualWidth, this.E.ActualHeight);  
    1239.                 nextPage = C;  
    1240.                 prevPage = F;  
    1241.                 leftPage = A;  
    1242.                 rightPage = B;  
    1243.                 leftTopPage = E;  
    1244.                 rightTopPage = D;  
    1245.                 nextTrans = transC;  
    1246.                 prevTrans = transF;  
    1247.                 //E.PointerPressed -= this.PointerPressed;  
    1248.                 //F.PointerPressed -= this.PointerPressed;  
    1249.                 //A.PointerPressed += this.PointerPressed;  
    1250.                 //B.PointerPressed += this.PointerPressed;  
    1251.                 break;  
    1252.             default:  
    1253.                 break;  
    1254.         }  
    1255.         stShadowSplitInnerLeft.Opacity = 0;  
    1256.         stShadowSplitInnerRight.Opacity = 0;  
    1257.         stShadowSplitOuterLeft.Opacity = 0;  
    1258.         stShadowSplitOuterRight.Opacity = 0;  
    1259.         outerRightTrans.TranslateX = 0;  
    1260.         innerRightTrans.TranslateX = 0;  
    1261.         outerLeftTrans.TranslateX = 0;  
    1262.         innerLeftTrans.TranslateX = 0;  
    1263.         marginLeftTrans.TranslateX = 0;  
    1264.         marginRightTrans.TranslateX = 0;  
    1265.         leftTopPage.Background = leftBrush;  
    1266.         prevPage.Background = rightBrush;  
    1267.         leftPage.Background = leftBrush;  
    1268.         rightPage.Background = rightBrush;  
    1269.         nextPage.Background = leftBrush;  
    1270.         rightTopPage.Background = rightBrush;  
    1271.     }  
    1272.     #endregion  
    1273.  
    1274.     #region GetCropBookBrush  
    1275.     private async Task GetCropBrush()  
    1276.     {  
    1277.         if (null != this.BookBackgroundBrush)  
    1278.         {  
    1279.             var orginSource = this.BookBackgroundBrush.ImageSource as BitmapImage;  
    1280.             if (!orginSource.UriSource.AbsolutePath.Equals(string.Empty))  
    1281.             {  
    1282.                 var uri = new Uri("ms-appx://" + orginSource.UriSource.AbsolutePath);  
    1283.                 try  
    1284.                 {  
    1285.                     var file = await StorageFile.GetFileFromApplicationUriAsync(uri);  
    1286.                     WriteableBitmap leftSource = new WriteableBitmap(Convert.ToInt32(offsetWidth * 2), Convert.ToInt32(offsetHeight));  
    1287.                     await LoadAsync(leftSource, file);  
    1288.                     WriteableBitmap rightSource = new WriteableBitmap(Convert.ToInt32(offsetWidth * 2), Convert.ToInt32(offsetHeight));  
    1289.                     await LoadAsync(rightSource, file);  
    1290.                     leftBrush = new ImageBrush();  
    1291.                     rightBrush = new ImageBrush();  
    1292.                     rightBrush.Stretch = Stretch.Fill;  
    1293.                     leftBrush.Stretch = Stretch.Fill;  
    1294.                     leftSource = Crop(leftSource, 0, 0, Convert.ToInt32(offsetWidth), Convert.ToInt32(offsetHeight));  
    1295.                     leftBrush.ImageSource = leftSource;  
    1296.                     rightSource = Crop(rightSource, Convert.ToInt32(offsetWidth), 0, Convert.ToInt32(offsetWidth * 2), Convert.ToInt32(offsetHeight));  
    1297.                     rightBrush.ImageSource = rightSource;  
    1298.                 }  
    1299.                 catch  
    1300.                 {  
    1301.                 }  
    1302.             }  
    1303.         }  
    1304.     }  
    1305.     #endregion  
    1306.  
    1307.     #region LoadWriteableBitmap  
    1308.     public async Task<WriteableBitmap> LoadAsync(  
    1309.         WriteableBitmap writeableBitmap,  
    1310.        StorageFile storageFile)  
    1311.     {  
    1312.         using (var stream = await storageFile.OpenReadAsync())  
    1313.         {  
    1314.             await writeableBitmap.SetSourceAsync(  
    1315.                 stream);  
    1316.         }  
    1317.         return writeableBitmap;  
    1318.     }  
    1319.  
    1320.     #endregion  
    1321.  
    1322.     #region SetShadowOperacity  
    1323.     private async void SetShadowOperacity(double pos, double pageWidth, bool direction)  
    1324.     {  
    1325.         var opacity = await Task.Run(() =>  
    1326.         {  
    1327.             double num = (pageWidth - pos) / 2.0;  
    1328.             double num2 = Math.Abs((double)((pageWidth / 2.0) - num));  
    1329.             return (1.0 * (1.0 - (num2 / (pageWidth / 2.0))));  
    1330.         });  
    1331.         if (direction)  
    1332.         {  
    1333.             this.stShadowSplitOuterLeft.Opacity = opacity;  
    1334.             this.stShadowSplitInnerLeft.Opacity = opacity;  
    1335.             this.stShadowMarginLeft.Opacity = opacity;  
    1336.         }  
    1337.         else  
    1338.         {  
    1339.             this.stShadowSplitOuterRight.Opacity = opacity;  
    1340.             this.stShadowSplitInnerRight.Opacity = opacity;  
    1341.             this.stShadowMarginRight.Opacity = opacity;  
    1342.         }  
    1343.     }  
    1344.     #endregion  
    1345.     #endregion  
    1346. }  
    1347.   
    1348. /// <summary>  
    1349. /// 抛出需要加载的项数据  
    1350. /// </summary>  
    1351. public class FlipLoadArgs : EventArgs  
    1352. {  
    1353.     public readonly List<object> needItems;  
    1354.     public readonly bool isNext;  
    1355.   
    1356.     public FlipLoadArgs(List<object> _needItems, bool _isNext)  
    1357.     {  
    1358.         this.needItems = _needItems;  
    1359.         this.isNext = _isNext;  
    1360.     }  
    1361. }  
    1362.   
    1363. public class FlipEventArgs : EventArgs  
    1364. {  
    1365.     public readonly bool isNext;  
    1366.   
    1367.     public FlipEventArgs(bool _isNext)  
    1368.     {  
    1369.         this.isNext = _isNext;  
    1370.     }  
    1371. }  
     
    1. <ResourceDictionary  
    2.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    3.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    4.     xmlns:local="using:WinRTXamlToolkit.Controls">  
    5.   
    6.     <Style TargetType="local:FlipBookControl">  
    7.         <Setter Property="Template">  
    8.             <Setter.Value>  
    9.                 <ControlTemplate TargetType="local:FlipBookControl">  
    10.                     <Grid   
    11.                         x:Name="grdContent"   
    12.                         Background="{TemplateBinding Background}">  
    13.                         <Grid.RowDefinitions>  
    14.                             <RowDefinition Height="30*"/>  
    15.                             <RowDefinition Height="750*"/>  
    16.                             <RowDefinition Height="30*"/>  
    17.                         </Grid.RowDefinitions>  
    18.                         <Grid.ColumnDefinitions>  
    19.                             <ColumnDefinition Width="50*"/>  
    20.                             <ColumnDefinition Width="600*"/>  
    21.                             <ColumnDefinition Width="600*"/>  
    22.                             <ColumnDefinition Width="50*"/>  
    23.                         </Grid.ColumnDefinitions>  
    24.                         <Image   
    25.                             x:Name="bookContainer"   
    26.                             Stretch="Fill"   
    27.                             Canvas.ZIndex="2"   
    28.                             Grid.ColumnSpan="4"   
    29.                             IsHitTestVisible="False"   
    30.                             Grid.RowSpan="3"/>  
    31.                         <Border   
    32.                             Grid.Row="1"   
    33.                             Grid.Column="1"   
    34.                             BorderThickness="0"  
    35.                             x:Name="C">  
    36.                             <Border.Clip>  
    37.                                 <RectangleGeometry x:Name="CRect">  
    38.                                 </RectangleGeometry>  
    39.                             </Border.Clip>  
    40.                             <Border.RenderTransform>  
    41.                                 <CompositeTransform x:Name="transC"></CompositeTransform>  
    42.                             </Border.RenderTransform>  
    43.                             <ContentPresenter x:Name="CPresenter" Style="{TemplateBinding ItemContainerStyle}"  
    44.                                               ContentTemplate="{TemplateBinding ItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"></ContentPresenter>  
    45.                         </Border>  
    46.                         <Border Grid.Row="1" Grid.Column="1" BorderThickness="0"  
    47.                             x:Name="D">  
    48.                             <Border.Clip>  
    49.                                 <RectangleGeometry x:Name="DRect">  
    50.                                 </RectangleGeometry>  
    51.                             </Border.Clip>  
    52.                             <Border.RenderTransform>  
    53.                                 <CompositeTransform x:Name="transD"></CompositeTransform>  
    54.                             </Border.RenderTransform>  
    55.                             <ContentPresenter x:Name="DPresenter" Style="{TemplateBinding ItemContainerStyle}"  
    56.                                               ContentTemplate="{TemplateBinding ItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"></ContentPresenter>  
    57.                         </Border>  
    58.                         <Border Grid.Row="1" Grid.Column="1" BorderThickness="0"  
    59.                             x:Name="E">  
    60.                             <Border.Clip>  
    61.                                 <RectangleGeometry x:Name="ERect">  
    62.                                 </RectangleGeometry>  
    63.                             </Border.Clip>  
    64.                             <Border.RenderTransform>  
    65.                                 <CompositeTransform x:Name="transE"/>  
    66.                             </Border.RenderTransform>  
    67.                             <ContentPresenter x:Name="EPresenter" Style="{TemplateBinding ItemContainerStyle}"  
    68.                                               ContentTemplate="{TemplateBinding ItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"></ContentPresenter>  
    69.                         </Border>  
    70.                         <Border Grid.Row="1" Grid.Column="1" BorderThickness="0"  
    71.                             x:Name="F">  
    72.                             <Border.Clip>  
    73.                                 <RectangleGeometry x:Name="FRect">  
    74.                                 </RectangleGeometry>  
    75.                             </Border.Clip>  
    76.                             <Border.RenderTransform>  
    77.                                 <CompositeTransform x:Name="transF"></CompositeTransform>  
    78.                             </Border.RenderTransform>  
    79.                             <ContentPresenter x:Name="FPresenter" Style="{TemplateBinding ItemContainerStyle}"  
    80.                                               ContentTemplate="{TemplateBinding ItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"></ContentPresenter>  
    81.                         </Border>  
    82.                         <Border Grid.Row="1" Grid.Column="1" BorderThickness="0"  
    83.                             x:Name="A">  
    84.                             <Border.Clip>  
    85.                                 <RectangleGeometry x:Name="ARect">  
    86.                                 </RectangleGeometry>  
    87.                             </Border.Clip>  
    88.                             <Border.RenderTransform>  
    89.                                 <CompositeTransform x:Name="transA"></CompositeTransform>  
    90.                             </Border.RenderTransform>  
    91.                             <ContentPresenter x:Name="APresenter" Style="{TemplateBinding ItemContainerStyle}"  
    92.                                               ContentTemplate="{TemplateBinding ItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"></ContentPresenter>  
    93.                         </Border>  
    94.                         <Border Grid.Row="1" Grid.Column="1"  BorderThickness="0"  
    95.                                 x:Name="B">  
    96.                             <Border.Clip>  
    97.                                 <RectangleGeometry x:Name="BRect">  
    98.                                 </RectangleGeometry>  
    99.                             </Border.Clip>  
    100.                             <Border.RenderTransform>  
    101.                                 <CompositeTransform x:Name="transB"/>  
    102.                             </Border.RenderTransform>  
    103.                             <ContentPresenter x:Name="BPresenter" Style="{TemplateBinding ItemContainerStyle}"  
    104.                                               ContentTemplate="{TemplateBinding ItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"></ContentPresenter>  
    105.                         </Border>  
    106.                         <StackPanel  Canvas.ZIndex="3"  
    107.                             x:Name="stShadowSplitOuterLeft"   
    108.                             Width="43"   
    109.                             Opacity="0"  
    110.                             Grid.Row="1"    
    111.                             Grid.Column="1"  
    112.                             HorizontalAlignment="Left" Margin="-43,0,0,0" RenderTransformOrigin="0.5,0.5">  
    113.                             <StackPanel.RenderTransform>  
    114.                                 <CompositeTransform x:Name="outerLeftTrans" TranslateX="0"/>  
    115.                             </StackPanel.RenderTransform>  
    116.                             <StackPanel.Background>  
    117.                                 <LinearGradientBrush EndPoint="0,0" StartPoint="1,0">  
    118.                                     <GradientStop Color="#99000000"/>  
    119.                                     <GradientStop Color="Transparent" Offset="1"/>  
    120.                                 </LinearGradientBrush>  
    121.                             </StackPanel.Background>  
    122.                         </StackPanel>  
    123.                         <StackPanel Canvas.ZIndex="3"  
    124.                             x:Name="stShadowSplitInnerLeft"   
    125.                             Width="51"   
    126.                             Opacity="0"  
    127.                             Grid.Row="1"    
    128.                             Grid.Column="1"  
    129.                             HorizontalAlignment="Left" RenderTransformOrigin="0.5,0.5">  
    130.                             <StackPanel.RenderTransform>  
    131.                                 <CompositeTransform x:Name="innerLeftTrans" TranslateX="0"/>  
    132.                             </StackPanel.RenderTransform>  
    133.                             <StackPanel.Background>  
    134.                                 <LinearGradientBrush EndPoint="1,1" StartPoint="0,1">  
    135.                                     <GradientStop Color="#99000000"/>  
    136.                                     <GradientStop Color="#01FFFFFF" Offset="1"/>  
    137.                                 </LinearGradientBrush>  
    138.                             </StackPanel.Background>  
    139.                         </StackPanel>  
    140.                         <StackPanel Canvas.ZIndex="3"  
    141.                             x:Name="stShadowSplitOuterRight"   
    142.                             Width="43"  
    143.                             Opacity="0"  
    144.                             Grid.Row="1"    
    145.                             Grid.Column="2"  
    146.                             HorizontalAlignment="Right" Margin="0,0,-43,0" RenderTransformOrigin="0.5,0.5">  
    147.                             <StackPanel.RenderTransform>  
    148.                                 <CompositeTransform x:Name="outerRightTrans" TranslateX="0"/>  
    149.                             </StackPanel.RenderTransform>  
    150.                             <StackPanel.Background>  
    151.                                 <LinearGradientBrush EndPoint="1,1" StartPoint="0,1">  
    152.                                     <GradientStop Color="#99000000"/>  
    153.                                     <GradientStop Color="Transparent" Offset="1"/>  
    154.                                 </LinearGradientBrush>  
    155.                             </StackPanel.Background>  
    156.                         </StackPanel>  
    157.                         <StackPanel  Canvas.ZIndex="3"  
    158.                             x:Name="stShadowSplitInnerRight"   
    159.                             Width="51"   
    160.                             Opacity="0"  
    161.                             Grid.Row="1"    
    162.                             Grid.Column="2"  
    163.                             HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5">  
    164.                             <StackPanel.RenderTransform>  
    165.                                 <CompositeTransform x:Name="innerRightTrans" TranslateX="0"/>  
    166.                             </StackPanel.RenderTransform>  
    167.                             <StackPanel.Background>  
    168.                                 <LinearGradientBrush EndPoint="0,0" StartPoint="1,0">  
    169.                                     <GradientStop Color="#99000000"/>  
    170.                                     <GradientStop Color="#01FFFFFF" Offset="1"/>  
    171.                                 </LinearGradientBrush>  
    172.                             </StackPanel.Background>  
    173.                         </StackPanel>  
    174.                         <StackPanel x:Name="stShadowMarginLeft" Width="30" HorizontalAlignment="Left"  
    175.                     Opacity="0" Grid.Row="1" Grid.Column="1" Canvas.ZIndex="3">  
    176.                             <StackPanel.RenderTransform>  
    177.                                 <CompositeTransform x:Name="marginLeftTrans" TranslateX="0"/>  
    178.                             </StackPanel.RenderTransform>  
    179.                             <StackPanel.Background>  
    180.                                 <LinearGradientBrush EndPoint="1,1" StartPoint="0,1">  
    181.                                     <GradientStop Color="#99000000"/>  
    182.                                     <GradientStop Color="Transparent" Offset="1"/>  
    183.                                 </LinearGradientBrush>  
    184.                             </StackPanel.Background>  
    185.                         </StackPanel>  
    186.                         <StackPanel x:Name="stShadowMarginRight" Width="30" HorizontalAlignment="Right"  
    187.                     Opacity="0" Grid.Row="1" Grid.Column="2" Canvas.ZIndex="3">  
    188.                             <StackPanel.RenderTransform>  
    189.                                 <CompositeTransform x:Name="marginRightTrans" TranslateX="0"/>  
    190.                             </StackPanel.RenderTransform>  
    191.                             <StackPanel.Background>  
    192.                                 <LinearGradientBrush EndPoint="0,0" StartPoint="1,0">  
    193.                                     <GradientStop Color="#99000000"/>  
    194.                                     <GradientStop Color="Transparent" Offset="1"/>  
    195.                                 </LinearGradientBrush>  
    196.                             </StackPanel.Background>  
    197.                         </StackPanel>  
    198.                     </Grid>  
    199.                 </ControlTemplate>  
    200.             </Setter.Value>  
    201.         </Setter>  
    202.     </Style>  
    203. </ResourceDictionary>  


     

    Sample: 使用方法

      <local:FlipBookControl x:Name="fbc"  Speed="10"
                                                ItemTemplate="{StaticResource BookTemplate}">
                <local:FlipBookControl.Background>
                    <ImageBrush ImageSource="ms-appx:///Assets/bookbox-hori.png"/>
                </local:FlipBookControl.Background>
                <local:FlipBookControl.BookBackgroundBrush>
                    <ImageBrush ImageSource="ms-appx:///Assets/bg-7.jpg"/>
                </local:FlipBookControl.BookBackgroundBrush>
            </local:FlipBookControl>

    支持ItemsSource 数据源 以及ItemTemplate Binding

    DisposeAction  和RestoreItem 2个依赖项 请在使用前填写。用于释放图片流 以及恢复 源

    欢迎讨论,分享经验,以及更优的方法。

  • 相关阅读:
    进程池,线程池,协程,gevent模块,协程实现单线程服务端与多线程客户端通信,IO模型
    线程相关 GIL queue event 死锁与递归锁 信号量l
    生产者消费者模型 线程相关
    进程的开启方式 进程的join方法 进程间的内存隔离 其他相关方法 守护进程 互斥锁
    udp协议 及相关 利用tcp上传文件 socketserver服务
    socket套接字 tcp协议下的粘包处理
    常用模块的完善 random shutil shevle 三流 logging
    day 29 元类
    Django入门
    MySQL多表查询
  • 原文地址:https://www.cnblogs.com/CharlesGrant/p/3639393.html
Copyright © 2011-2022 走看看