|
1 |
| -using Microsoft.UI.Text; |
| 1 | +using CollapseLauncher.Helper.Animation; |
| 2 | +using CommunityToolkit.WinUI.Controls; |
| 3 | +using Microsoft.UI.Text; |
2 | 4 | using Microsoft.UI.Xaml;
|
3 | 5 | using Microsoft.UI.Xaml.Controls;
|
4 | 6 | using Microsoft.UI.Xaml.Controls.Primitives;
|
@@ -141,5 +143,46 @@ internal static CornerRadius AttachRoundedKindCornerRadius(Control element)
|
141 | 143 |
|
142 | 144 | return initialRadius;
|
143 | 145 | }
|
| 146 | + |
| 147 | + internal static void FindAndSetTextBlockWrapping(this UIElement element, TextWrapping wrap = TextWrapping.Wrap, HorizontalAlignment posAlign = HorizontalAlignment.Center, TextAlignment textAlign = TextAlignment.Center, bool recursiveAssignment = false, bool isParentAButton = false) |
| 148 | + { |
| 149 | + if (element is not null && element is TextBlock textBlock) |
| 150 | + { |
| 151 | + textBlock.TextWrapping = wrap; |
| 152 | + if (isParentAButton) |
| 153 | + { |
| 154 | + textBlock.HorizontalAlignment = posAlign; |
| 155 | + textBlock.HorizontalTextAlignment = textAlign; |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + if (!recursiveAssignment) return; |
| 160 | + |
| 161 | + if (element is ButtonBase button) |
| 162 | + { |
| 163 | + if (button.Content is UIElement buttonContent) |
| 164 | + buttonContent.FindAndSetTextBlockWrapping(wrap, posAlign, textAlign, recursiveAssignment, true); |
| 165 | + else if (button.Content is string buttonString) |
| 166 | + button.Content = new TextBlock { Text = buttonString, TextWrapping = wrap, HorizontalAlignment = HorizontalAlignment.Center }; |
| 167 | + } |
| 168 | + |
| 169 | + if (element is Panel panel) |
| 170 | + foreach (UIElement childrenElement in panel.Children!) |
| 171 | + childrenElement.FindAndSetTextBlockWrapping(wrap, posAlign, textAlign, recursiveAssignment, isParentAButton); |
| 172 | + |
| 173 | + if (element is ScrollViewer scrollViewer && scrollViewer.Content is UIElement elementInner) |
| 174 | + elementInner.FindAndSetTextBlockWrapping(wrap, posAlign, textAlign, recursiveAssignment, isParentAButton); |
| 175 | + |
| 176 | + if (element is ContentControl contentControl && (element is SettingsCard || element is Expander) && contentControl.Content is UIElement contentControlInner) |
| 177 | + { |
| 178 | + contentControlInner.FindAndSetTextBlockWrapping(wrap, posAlign, textAlign, recursiveAssignment, isParentAButton); |
| 179 | + |
| 180 | + if (contentControl is Expander expander && expander.Header is UIElement expanderHeader) |
| 181 | + expanderHeader.FindAndSetTextBlockWrapping(wrap, posAlign, textAlign, recursiveAssignment, isParentAButton); |
| 182 | + } |
| 183 | + |
| 184 | + if (element is InfoBar infoBar && infoBar.Content is UIElement infoBarInner) |
| 185 | + infoBarInner.FindAndSetTextBlockWrapping(wrap, posAlign, textAlign, recursiveAssignment, isParentAButton); |
| 186 | + } |
144 | 187 | }
|
145 | 188 | }
|
0 commit comments