|
18 | 18 | using System.Threading.Tasks; |
19 | 19 | using Windows.UI.Core; |
20 | 20 | using System.Collections.ObjectModel; |
| 21 | +using System.Numerics; |
21 | 22 |
|
22 | 23 |
|
23 | 24 |
|
@@ -105,36 +106,40 @@ void ReloadDevices() |
105 | 106 |
|
106 | 107 | } |
107 | 108 |
|
108 | | - void EnableMargin() |
| 109 | + void AnimateImageGrid(double targetWidth, double targetHeight, double offsetX, double offsetY, double durationMs = 300) |
109 | 110 | { |
110 | 111 | var visual = ElementCompositionPreview.GetElementVisual(ImageGrid); |
111 | 112 | var compositor = visual.Compositor; |
112 | 113 |
|
113 | | - // Calculate offset you want (simulates Margin change) |
114 | | - var targetOffset = new System.Numerics.Vector3( |
115 | | - x: (float)(20 + PhotoButton.ActualWidth * 2), |
116 | | - y: (float)(32 + 20), |
117 | | - z: 0f); |
| 114 | + var offsetAnim = compositor.CreateVector3KeyFrameAnimation(); |
| 115 | + offsetAnim.InsertKeyFrame(1f, new Vector3((float)offsetX, (float)offsetY, 0)); |
| 116 | + offsetAnim.Duration = TimeSpan.FromMilliseconds(durationMs); |
| 117 | + visual.StartAnimation(nameof(visual.Offset), offsetAnim); |
| 118 | + |
| 119 | + var sizeAnim = compositor.CreateVector2KeyFrameAnimation(); |
| 120 | + sizeAnim.InsertKeyFrame(1f, new Vector2((float)targetWidth, (float)targetHeight)); |
| 121 | + sizeAnim.Duration = TimeSpan.FromMilliseconds(durationMs); |
| 122 | + visual.StartAnimation("Size", sizeAnim); |
| 123 | + |
| 124 | + ImageViewbox.Stretch = (targetWidth > targetHeight) ? Stretch.Uniform : Stretch.UniformToFill; |
| 125 | + } |
118 | 126 |
|
119 | | - var animation = compositor.CreateVector3KeyFrameAnimation(); |
120 | | - animation.InsertKeyFrame(1f, targetOffset); |
121 | | - animation.Duration = TimeSpan.FromMilliseconds(300); |
| 127 | + void EnableMargin() |
| 128 | + { |
| 129 | + double newWidth = ImageGrid.ActualWidth - 20 - PhotoButton.ActualWidth - PhotoButton.Margin.Left; // example |
| 130 | + double newHeight = ImageGrid.ActualHeight - 40 - SettingsViewer.ActualHeight; |
122 | 131 |
|
123 | | - visual.StartAnimation(nameof(visual.Offset), animation); |
| 132 | + double offsetX = -20; |
| 133 | + double offsetY = 32 + 20; |
| 134 | + |
| 135 | + AnimateImageGrid(newWidth, newHeight, offsetX, offsetY); |
124 | 136 |
|
125 | 137 | ImageViewbox.Stretch = Stretch.Uniform; |
126 | 138 | } |
127 | 139 |
|
128 | 140 | void DisableMargin() |
129 | 141 | { |
130 | | - var visual = ElementCompositionPreview.GetElementVisual(ImageGrid); |
131 | | - var compositor = visual.Compositor; |
132 | | - |
133 | | - var animation = compositor.CreateVector3KeyFrameAnimation(); |
134 | | - animation.InsertKeyFrame(1f, new System.Numerics.Vector3(0, 0, 0)); |
135 | | - animation.Duration = TimeSpan.FromMilliseconds(300); |
136 | | - |
137 | | - visual.StartAnimation(nameof(visual.Offset), animation); |
| 142 | + AnimateImageGrid(ImageGrid.ActualWidth, ImageGrid.ActualHeight, 0, 0); |
138 | 143 |
|
139 | 144 | ImageViewbox.Stretch = Stretch.UniformToFill; |
140 | 145 | } |
|
0 commit comments