// (c) Copyright Microsoft Corporation. // This source is subject to the Microsoft Public License (Ms-PL). // Please see http://go.microsoft.com/fwlink/?LinkID=131993] for details. // All other rights reserved. namespace System.Windows.Controls.Primitives { /// /// Clips a ratio of its content. /// /// Preview public abstract class Clipper : ContentControl { #region public double RatioVisible /// /// Gets or sets the percentage of the item visible. /// public double RatioVisible { get { return (double)GetValue(RatioVisibleProperty); } set { SetValue(RatioVisibleProperty, value); } } /// /// Identifies the RatioVisible dependency property. /// public static readonly DependencyProperty RatioVisibleProperty = DependencyProperty.Register( "RatioVisible", typeof(double), typeof(Clipper), new PropertyMetadata(1.0, OnRatioVisibleChanged)); /// /// RatioVisibleProperty property changed handler. /// /// PartialView that changed its RatioVisible. /// Event arguments. private static void OnRatioVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Clipper source = (Clipper)d; double oldValue = (double)e.OldValue; double newValue = (double)e.NewValue; source.OnRatioVisibleChanged(oldValue, newValue); } /// /// RatioVisibleProperty property changed handler. /// /// Old value. /// New value. protected virtual void OnRatioVisibleChanged(double oldValue, double newValue) { if (newValue >= 0.0 && newValue <= 1.0) { ClipContent(); } else { if (newValue < 0.0) { this.RatioVisible = 0.0; } else if (newValue > 1.0) { this.RatioVisible = 1.0; } } } #endregion public double RatioVisible /// /// Initializes a new instance of the Clipper class. /// protected Clipper() { this.SizeChanged += delegate { ClipContent(); }; } /// /// Updates the clip geometry. /// protected abstract void ClipContent(); } }