using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; using System.Windows; namespace ivf_tl_Manage { public class ResolutionAdapter { public double wB { get; set; } public double hB { get; set; } public void EnumVisualTree(int Ident, Visual visualObj) { wB = GetScreenWidth() / 1920d; hB = GetScreenHeight() / 1080d; for (int i = 0; i < VisualTreeHelper.GetChildrenCount(visualObj); i++) { Visual childVisual = (Visual)VisualTreeHelper.GetChild(visualObj, i); if (childVisual is Border) Console.WriteLine(""); var uie = childVisual as FrameworkElement; if (uie != null) { SetElement(wB, hB, uie); if (uie is Grid) { Grid grid = uie as Grid; grid.Width = grid.Width * wB; grid.Height = grid.Height * hB; var cols = grid.ColumnDefinitions.ToArray(); foreach (var col in cols) { col.Width =new GridLength(col.ActualWidth*wB); } } if (uie is TextBlock) { var tbElement = uie as TextBlock; tbElement.FontSize = tbElement.FontSize * wB; } if (uie is Label) { var lblElement = uie as Label; lblElement.FontSize = lblElement.FontSize * wB; } if (uie is Border) { var borderElement = uie as Border; CornerRadius radius = borderElement.CornerRadius; borderElement.CornerRadius = new CornerRadius(radius.TopLeft * hB, radius.TopRight * hB, radius.BottomRight * hB, radius.BottomLeft * hB); } if (uie is Ellipse) { Ellipse ellipse = uie as Ellipse; double temp = ellipse.Height; ellipse.Width = temp * hB; ellipse.Height = temp * hB; } } EnumVisualTree(Ident + 1, childVisual); } } private void SetElement(double wB, double hB, FrameworkElement uie) { uie.Width = uie.Width * wB; uie.Height = uie.Height * hB; uie.SetValue(Canvas.LeftProperty, (double)uie.GetValue(Canvas.LeftProperty) * wB); uie.SetValue(Canvas.TopProperty, (double)uie.GetValue(Canvas.TopProperty) * hB); uie.Margin = new Thickness(uie.Margin.Left * wB, uie.Margin.Top * hB, uie.Margin.Right * wB, uie.Margin.Bottom * hB); } public double GetScreenWidth() { return SystemParameters.PrimaryScreenWidth; } public double GetScreenHeight() { return SystemParameters.PrimaryScreenHeight; } } }