master
cs 82 lines 3.49 KB
Raw
1 // Copyright (C) Microsoft Corporation. All rights reserved.
2
3 using Microsoft.UI.Xaml;
4 using Microsoft.UI.Xaml.Controls;
5 using Windows.UI.ViewManagement;
6
7 namespace WslSettings.Controls
8 {
9 public sealed partial class OOBEContent : UserControl
10 {
11 // Constants for hero image height calculations
12 private const double BaseImageHeight = 280.0;
13 private const double MinimumImageHeight = 200.0;
14
15 private static readonly UISettings Settings = new UISettings();
16
17 public OOBEContent()
18 {
19 this.InitializeComponent();
20
21 // Set initial hero image height based on current text scaling
22 UpdateHeroImageHeight();
23
24 // Subscribe to text scale factor changes for dynamic updates
25 Settings.TextScaleFactorChanged += OnTextScaleFactorChanged;
26
27 // Ensure event cleanup when control is unloaded
28 this.Unloaded += (s, e) => Settings.TextScaleFactorChanged -= OnTextScaleFactorChanged;
29 }
30
31 private void UpdateHeroImageHeight()
32 {
33 double textScaleFactor = Settings.TextScaleFactor;
34
35 // Reduce image height when text scaling increases to preserve content space
36 // Use inverse relationship: as text gets larger, image gets proportionally smaller
37 HeroImageHeight = Math.Max(BaseImageHeight / textScaleFactor, MinimumImageHeight);
38 }
39
40 private void OnTextScaleFactorChanged(UISettings sender, object args)
41 {
42 // Update hero image height when text scaling changes at runtime
43 this.DispatcherQueue.TryEnqueue(() => UpdateHeroImageHeight());
44 }
45
46 public string Title
47 {
48 get { return (string)GetValue(TitleProperty); }
49 set { SetValue(TitleProperty, value); }
50 }
51
52 public string Description
53 {
54 get => (string)GetValue(DescriptionProperty);
55 set => SetValue(DescriptionProperty, value);
56 }
57
58 public string HeroImage
59 {
60 get => (string)GetValue(HeroImageProperty);
61 set => SetValue(HeroImageProperty, value);
62 }
63
64 public double HeroImageHeight
65 {
66 get { return (double)GetValue(HeroImageHeightProperty); }
67 set { SetValue(HeroImageHeightProperty, value); }
68 }
69
70 public object PageContent
71 {
72 get { return (object)GetValue(PageContentProperty); }
73 set { SetValue(PageContentProperty, value); }
74 }
75
76 public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(OOBEContent), new PropertyMetadata(default(string)));
77 public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(OOBEContent), new PropertyMetadata(default(string)));
78 public static readonly DependencyProperty HeroImageProperty = DependencyProperty.Register("HeroImage", typeof(string), typeof(OOBEContent), new PropertyMetadata(default(string)));
79 public static readonly DependencyProperty PageContentProperty = DependencyProperty.Register("PageContent", typeof(object), typeof(OOBEContent), new PropertyMetadata(new Grid()));
80 public static readonly DependencyProperty HeroImageHeightProperty = DependencyProperty.Register("HeroImageHeight", typeof(double), typeof(OOBEContent), new PropertyMetadata(BaseImageHeight));
81 }
82 }