Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Themes / Aero / Microsoft / Windows / Themes / ProgressBarHighlightConverter.cs / 1 / ProgressBarHighlightConverter.cs
//---------------------------------------------------------------------------- // // Copyright (C) by Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Globalization; using System.Threading; using System.Windows; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Animation; namespace Microsoft.Windows.Themes { ////// The ProgressBarHighlightConverter class /// public class ProgressBarHighlightConverter : IMultiValueConverter { ////// Creates the brush for the ProgressBar /// /// ForegroundBrush, IsIndeterminate, Width, Height /// /// /// ///Brush for the ProgressBar public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { // // Parameter Validation // Type doubleType = typeof(double); if (values == null || (values.Length != 3) || (values[0] == null) || (values[1] == null) || (values[2] == null) || !typeof(Brush).IsAssignableFrom(values[0].GetType()) || !doubleType.IsAssignableFrom(values[1].GetType()) || !doubleType.IsAssignableFrom(values[2].GetType())) { return null; } // // Conversion // Brush brush = (Brush)values[0]; double width = (double)values[1]; double height = (double)values[2]; // if an invalid height, return a null brush if (width <= 0.0 || Double.IsInfinity(width) || Double.IsNaN(width) || height <= 0.0 || Double.IsInfinity(height) || Double.IsNaN(height) ) { return null; } DrawingBrush newBrush = new DrawingBrush(); // Create a Drawing Brush that is 2x longer than progress bar track // // +-------------+.............. // | highlight | empty : // +-------------+.............: // // This brush will animate to the right. double twiceWidth = width * 2.0; // Set the viewport and viewbox to the 2*size of the progress region newBrush.Viewport = newBrush.Viewbox = new Rect(-width, 0, twiceWidth, height); newBrush.ViewportUnits = newBrush.ViewboxUnits = BrushMappingMode.Absolute; newBrush.TileMode = TileMode.None; newBrush.Stretch = Stretch.None; DrawingGroup myDrawing = new DrawingGroup(); DrawingContext myDrawingContext = myDrawing.Open(); // Draw the highlight myDrawingContext.DrawRectangle(brush, null, new Rect(-width, 0, width, height)); // Animate the Translation TimeSpan translateTime = TimeSpan.FromSeconds(twiceWidth / 200.0); // travel at 200px /second TimeSpan pauseTime = TimeSpan.FromSeconds(1.0); // pause 1 second between animations DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames(); animation.BeginTime = TimeSpan.Zero; animation.Duration = new Duration(translateTime + pauseTime); animation.RepeatBehavior = RepeatBehavior.Forever; animation.KeyFrames.Add(new LinearDoubleKeyFrame(twiceWidth, translateTime)); TranslateTransform translation = new TranslateTransform(); // Set the animation to the XProperty translation.BeginAnimation(TranslateTransform.XProperty, animation); // Set the animated translation on the brush newBrush.Transform = translation; myDrawingContext.Close(); newBrush.Drawing = myDrawing; return newBrush; } ////// Not Supported /// /// value, as produced by target /// target types /// converter parameter /// culture information ///Nothing public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { return null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // Copyright (C) by Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Globalization; using System.Threading; using System.Windows; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Animation; namespace Microsoft.Windows.Themes { ////// The ProgressBarHighlightConverter class /// public class ProgressBarHighlightConverter : IMultiValueConverter { ////// Creates the brush for the ProgressBar /// /// ForegroundBrush, IsIndeterminate, Width, Height /// /// /// ///Brush for the ProgressBar public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { // // Parameter Validation // Type doubleType = typeof(double); if (values == null || (values.Length != 3) || (values[0] == null) || (values[1] == null) || (values[2] == null) || !typeof(Brush).IsAssignableFrom(values[0].GetType()) || !doubleType.IsAssignableFrom(values[1].GetType()) || !doubleType.IsAssignableFrom(values[2].GetType())) { return null; } // // Conversion // Brush brush = (Brush)values[0]; double width = (double)values[1]; double height = (double)values[2]; // if an invalid height, return a null brush if (width <= 0.0 || Double.IsInfinity(width) || Double.IsNaN(width) || height <= 0.0 || Double.IsInfinity(height) || Double.IsNaN(height) ) { return null; } DrawingBrush newBrush = new DrawingBrush(); // Create a Drawing Brush that is 2x longer than progress bar track // // +-------------+.............. // | highlight | empty : // +-------------+.............: // // This brush will animate to the right. double twiceWidth = width * 2.0; // Set the viewport and viewbox to the 2*size of the progress region newBrush.Viewport = newBrush.Viewbox = new Rect(-width, 0, twiceWidth, height); newBrush.ViewportUnits = newBrush.ViewboxUnits = BrushMappingMode.Absolute; newBrush.TileMode = TileMode.None; newBrush.Stretch = Stretch.None; DrawingGroup myDrawing = new DrawingGroup(); DrawingContext myDrawingContext = myDrawing.Open(); // Draw the highlight myDrawingContext.DrawRectangle(brush, null, new Rect(-width, 0, width, height)); // Animate the Translation TimeSpan translateTime = TimeSpan.FromSeconds(twiceWidth / 200.0); // travel at 200px /second TimeSpan pauseTime = TimeSpan.FromSeconds(1.0); // pause 1 second between animations DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames(); animation.BeginTime = TimeSpan.Zero; animation.Duration = new Duration(translateTime + pauseTime); animation.RepeatBehavior = RepeatBehavior.Forever; animation.KeyFrames.Add(new LinearDoubleKeyFrame(twiceWidth, translateTime)); TranslateTransform translation = new TranslateTransform(); // Set the animation to the XProperty translation.BeginAnimation(TranslateTransform.XProperty, animation); // Set the animated translation on the brush newBrush.Transform = translation; myDrawingContext.Close(); newBrush.Drawing = myDrawing; return newBrush; } ////// Not Supported /// /// value, as produced by target /// target types /// converter parameter /// culture information ///Nothing public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { return null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ApplicationSecurityInfo.cs
- ImageFormat.cs
- WindowsProgressbar.cs
- ServiceOperationInfoTypeConverter.cs
- TreeNodeBinding.cs
- InputProcessorProfilesLoader.cs
- DbSetClause.cs
- ConsumerConnectionPointCollection.cs
- PointCollectionValueSerializer.cs
- SiteIdentityPermission.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- FrameworkElementAutomationPeer.cs
- KeyboardEventArgs.cs
- DataGridViewColumnConverter.cs
- CompilationRelaxations.cs
- XmlSerializableWriter.cs
- DecimalStorage.cs
- DeviceSpecificDesigner.cs
- WsdlImporter.cs
- ToolboxItem.cs
- WindowsFormsHostAutomationPeer.cs
- App.cs
- ListViewCancelEventArgs.cs
- InternalConfigRoot.cs
- LicenseContext.cs
- DropDownHolder.cs
- AttachedAnnotation.cs
- OrderedDictionary.cs
- StateRuntime.cs
- CodeCompileUnit.cs
- SqlIdentifier.cs
- ProcessStartInfo.cs
- SqlCaseSimplifier.cs
- FieldTemplateUserControl.cs
- AutomationAttributeInfo.cs
- DataGridViewCellStyleBuilderDialog.cs
- DbDataReader.cs
- DataConnectionHelper.cs
- DataQuery.cs
- DefaultValueAttribute.cs
- OLEDB_Enum.cs
- Comparer.cs
- SecurityContext.cs
- DataFormats.cs
- ProjectionPathSegment.cs
- XmlSchemaDatatype.cs
- SafeNativeMethods.cs
- OleDbConnectionFactory.cs
- DocumentSequence.cs
- LingerOption.cs
- UserControlBuildProvider.cs
- StringValueConverter.cs
- MatrixAnimationUsingKeyFrames.cs
- AsymmetricKeyExchangeDeformatter.cs
- ListViewSortEventArgs.cs
- IFlowDocumentViewer.cs
- MimeMultiPart.cs
- _LocalDataStore.cs
- NavigationHelper.cs
- ObjectCacheHost.cs
- FileInfo.cs
- StringExpressionSet.cs
- DictionaryBase.cs
- PositiveTimeSpanValidator.cs
- PasswordTextContainer.cs
- HttpException.cs
- SystemDropShadowChrome.cs
- WsatExtendedInformation.cs
- IMembershipProvider.cs
- ParserOptions.cs
- WebServiceData.cs
- UndirectedGraph.cs
- InstanceData.cs
- DesignerTransaction.cs
- VectorCollectionConverter.cs
- WebPartUserCapability.cs
- DrawingAttributesDefaultValueFactory.cs
- UseLicense.cs
- SmtpFailedRecipientsException.cs
- SafeArrayRankMismatchException.cs
- XmlSchemaSequence.cs
- NamedPermissionSet.cs
- OutputCacheProfileCollection.cs
- TypeDescriptor.cs
- OleDbErrorCollection.cs
- BindingManagerDataErrorEventArgs.cs
- ResXDataNode.cs
- JsonFormatWriterGenerator.cs
- ExecutionEngineException.cs
- SecurityCookieModeValidator.cs
- DifferencingCollection.cs
- Base64Encoder.cs
- GeneralTransform3DGroup.cs
- RowSpanVector.cs
- ClientProxyGenerator.cs
- CatalogPart.cs
- ConvertTextFrag.cs
- FunctionQuery.cs
- ComponentCollection.cs
- CircleHotSpot.cs