Cuando estaba utilizando la clase ScaleTransform para realizar un zoom sobre un control tenia el problema que el control al que hacia zoom sobresalia al tamaño del contenedor.
Ejemplo:
Realizando multiples investigaciones encontre la solucion a este problema :
Utilizar un grid como contenedor del control al que se le hara el zoom , declarando una fila y una columna con Height y Width en auto.
Codigo de ejemplo XAML:
CodeBehind:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace zoom_user_control { /// /// Interaction logic for UserControlToZoom.xaml /// public partial class UserControlToZoom : UserControl { public UserControlToZoom() { InitializeComponent(); } private void UserControl_MouseWheel(object sender, MouseWheelEventArgs e) { var delta = (e.Delta / 2000d).ToMultipleOf(0.05d); this.MediaElementZoom = Math.Round(this.MediaElementZoom + delta, 2); } /// /// Gets or sets the media element zoom. /// /// /// Gets or sets the media element zoom. /// public double MediaElementZoom { get { var m = this.lbl; if (m == null) return 1d; var transform = m.RenderTransform as ScaleTransform; if (transform == null) return 1d; return transform.ScaleX == null ? 1d : transform.ScaleX; } set { var m = this.lbl; if (m == null) return; var transform = m.RenderTransform as ScaleTransform; if (transform == null) { transform = new ScaleTransform(1, 1); m.RenderTransformOrigin = new Point(0.5, 0.5); m.RenderTransform = transform; } transform.ScaleX = value; transform.ScaleY = value; if (transform.ScaleX 5) { transform.ScaleX = 5; transform.ScaleY = 5; } } } } }
Extentions:
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace zoom_user_control { public static class Extentions { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double ToMultipleOf(this double value, double multiple) { var factor = Convert.ToInt32(value / multiple); return factor * multiple; } } }
Si les sirvio , no olviden comentar 🙂