|
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 |
|
5 | 5 | using System; |
| 6 | +using System.ComponentModel; |
6 | 7 | using Windows.UI.Xaml; |
7 | 8 | using Windows.UI.Xaml.Controls; |
8 | 9 | using Windows.UI.Xaml.Markup; |
@@ -78,8 +79,12 @@ public Type TargetType |
78 | 79 | DependencyProperty.Register(nameof(TargetType), typeof(Type), typeof(SwitchPresenter), new PropertyMetadata(null)); |
79 | 80 |
|
80 | 81 | /// <summary> |
81 | | - /// Gets or sets a value indicating whether the content is removed from the visual tree when switching between cases. |
| 82 | + /// Gets or sets a value indicating whether the content is removed from the visual tree when |
| 83 | + /// switching between cases. This calls <see cref="VisualTreeHelper.DisconnectChildrenRecursive(UIElement)"/> |
| 84 | + /// when switching between cases, so is only meant if the displayed case is never intended to be |
| 85 | + /// shown again. No explicit re-initialization of controls is provided by the <see cref="SwitchPresenter"/>. |
82 | 86 | /// </summary> |
| 87 | + [EditorBrowsable(EditorBrowsableState.Never)] |
83 | 88 | public bool IsVisualTreeDisconnectedOnChange { get; set; } |
84 | 89 |
|
85 | 90 | private static void OnSwitchCasesPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
@@ -176,14 +181,27 @@ private void EvaluateCases() |
176 | 181 | // Disconnect old content from visual tree. |
177 | 182 | if (CurrentCase != null && CurrentCase.Content != null && IsVisualTreeDisconnectedOnChange) |
178 | 183 | { |
179 | | - // TODO: If we disconnect here, we need to recreate later??? Need to Test... |
| 184 | + // When we disconnect here, we can't easily redo anything done here, so this is |
| 185 | + // an advanced option left open to specific scenarios for a developer. |
| 186 | + // It shouldn't come up in normaly usages, unless a developer intends each |
| 187 | + // case to only be displayed once. |
180 | 188 | VisualTreeHelper.DisconnectChildrenRecursive(CurrentCase.Content); |
181 | 189 | } |
182 | 190 |
|
183 | | - // Hookup new content. |
184 | | - Content = newcase.Content; |
| 191 | + // We don't have any cases or a default to go to, so go back to blank |
| 192 | + if (newcase == null) |
| 193 | + { |
| 194 | + Content = null; |
185 | 195 |
|
186 | | - CurrentCase = newcase; |
| 196 | + CurrentCase = null; |
| 197 | + } |
| 198 | + else |
| 199 | + { |
| 200 | + // Hookup new content. |
| 201 | + Content = newcase.Content; |
| 202 | + |
| 203 | + CurrentCase = newcase; |
| 204 | + } |
187 | 205 | } |
188 | 206 | } |
189 | 207 |
|
|
0 commit comments