实例介绍
【实例截图】
【核心代码】
#region License Revision: 0 Last Revised: 3/29/2006 8:21 AM /****************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This file is licensed under the Microsoft Public License (Ms-PL). A copy of the Ms-PL should accompany this file. If it does not, you can obtain a copy from: http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx ******************************************************************************/ #endregion // License using System; using System.IO; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Navigation; using System.Windows.Markup; using System.Xml; using System.Reflection; using Transitionals; using System.Collections.ObjectModel; using System.ComponentModel; using Microsoft.Win32; namespace TransitionTester { public partial class TransitionWindow { #region Constants /************************************************ * Constants ***********************************************/ private const string CellA = "CellA"; private const string CellB = "CellB"; #endregion // Constants #region Member Variables /************************************************ * Member Variables ***********************************************/ private ICollectionView view; #endregion // Member Variables #region Constructors /************************************************ * Constructors ***********************************************/ /// <summary> /// Initializes a new <see cref="TransitionWindow"/>. /// </summary> public TransitionWindow() { this.InitializeComponent(); // Get the default view for the transition types view = CollectionViewSource.GetDefaultView(App.CurrentApp.TransitionTypes); // Set the default sort view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); // Handle changes in currency view.CurrentChanged = new EventHandler(view_CurrentChanged); // Bind TransitionDS.ObjectType = null; TransitionTypesDS.ObjectType = null; TransitionTypesDS.ObjectInstance = App.CurrentApp.TransitionTypes; // Navigate to first item view.MoveCurrentToFirst(); } #endregion // Constructors #region Internal Methods /************************************************ * Internal Methods ***********************************************/ /// <summary> /// Activates a transition and displays it. /// </summary> /// <param name="transitionType"> /// The type of transition to activate. /// </param> private void ActivateTransition(Type transitionType) { // If no type, ignore if (transitionType == null) return; // Create the instance Transition transition = (Transition)Activator.CreateInstance(transitionType); // Bind TransitionDS.ObjectInstance = transition; App.CurrentApp.PropertyWindow.SelectedObject = transition; // Swap cells to show transition SwapCell(); } /// <summary> /// Loads transitions by allowing the user to browse for a transition assembly. /// </summary> private void BrowseLoadTransitions() { // Create the browser OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Assemblies (*.dll, *.exe)|*.dll;*.exe|All files (*.*)|*.*"; ofd.Multiselect = true; // Show the browse and if successful, try to load. if (ofd.ShowDialog(this) == true) { // Try to load each selected file foreach (string path in ofd.FileNames) { try { App.CurrentApp.LoadTransitions(path); } catch (Exception ex) { // Build the message string msg = string.Format("Error loading transitions:\r\n\r\n{0}\r\n\r\nContinue?", ex.Message); // Show message and ask to continue MessageBoxResult result = MessageBox.Show(msg, "Error", MessageBoxButton.YesNo, MessageBoxImage.Error); // If we shouldn't continue, break out of loop if (result != MessageBoxResult.Yes) { break; } } } } } /// <summary> /// Creates an animation cell for demonstrating a transition. /// </summary> /// <param name="style"> /// The style used to create the cell. /// </param> /// <returns> /// A <see cref="ContentControl"/> that represents the cell. /// </returns> private ContentControl CreateCell(Style style) { ContentControl c = new ContentControl(); c.Style = style; return c; } /// <summary> /// Displays the About dialog. /// </summary> private void ShowAbout() { AboutWindow about = new AboutWindow(); about.Owner = this; about.ShowDialog(); } /// <summary> /// Swaps the current cell, from A to B or from B to A. /// </summary> private void SwapCell() { ContentControl currentCell = (ContentControl)TransitionBox.Content; if ((currentCell == null) || (currentCell.Style == Resources[CellB])) { TransitionBox.Content = CreateCell((Style)Resources[CellA]); } else { TransitionBox.Content = CreateCell((Style)Resources[CellB]); } } #endregion // Internal Methods #region Overrides / Event Handlers /************************************************ * Overrides / Event Handlers ***********************************************/ private void About_Executed(object sender, RoutedEventArgs e) { ShowAbout(); } private void ABButton_Click(object sender, RoutedEventArgs e) { SwapCell(); } private void AButton_Click(object sender, RoutedEventArgs e) { TransitionBox.Content = CreateCell((Style)Resources[CellA]); } private void BButton_Click(object sender, RoutedEventArgs e) { TransitionBox.Content = CreateCell((Style)Resources[CellB]); } private void ClearButton_Click(object sender, RoutedEventArgs e) { TransitionBox.Content = null; } private void Exit_Executed(object sender, RoutedEventArgs e) { Close(); } private void Open_Executed(object sender, RoutedEventArgs e) { BrowseLoadTransitions(); } private void PropertyButton_Click(object sender, RoutedEventArgs e) { App.CurrentApp.TogglePropertyWindow(); } private void view_CurrentChanged(object sender, EventArgs e) { ActivateTransition((Type)view.CurrentItem); } #endregion // Overrides / Event Handlers #region Internal Properties /************************************************ * Internal Properties ***********************************************/ private ObjectDataProvider TransitionDS { get { return (ObjectDataProvider)Resources["TransitionDS"]; } } private ObjectDataProvider TransitionTypesDS { get { return (ObjectDataProvider)Resources["TransitionTypesDS"]; } } #endregion // Internal Properties } }
标签: 分页 wpf Transitionals
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论