|
4 | 4 |
|
5 | 5 | using System;
|
6 | 6 | using System.Collections;
|
| 7 | +using System.ComponentModel; |
7 | 8 | using System.Windows;
|
8 | 9 | using System.Windows.Controls;
|
9 | 10 | using System.Windows.Input;
|
@@ -33,7 +34,7 @@ namespace MahApps.Metro.Controls
|
33 | 34 | [TemplateVisualState(Name = "OpenCompactOverlayRight", GroupName = "DisplayModeStates")]
|
34 | 35 | [ContentProperty(nameof(Content))]
|
35 | 36 | [StyleTypedProperty(Property = nameof(ResizeThumbStyle), StyleTargetType = typeof(MetroThumb))]
|
36 |
| - public class SplitView : Control |
| 37 | + public class SplitView : ContentControl |
37 | 38 | {
|
38 | 39 | private Rectangle? lightDismissLayer;
|
39 | 40 | private RectangleGeometry? paneClipRectangle;
|
@@ -69,23 +70,6 @@ public double CompactPaneLength
|
69 | 70 | set => this.SetValue(CompactPaneLengthProperty, value);
|
70 | 71 | }
|
71 | 72 |
|
72 |
| - /// <summary>Identifies the <see cref="Content"/> dependency property.</summary> |
73 |
| - public static readonly DependencyProperty ContentProperty |
74 |
| - = DependencyProperty.Register(nameof(Content), |
75 |
| - typeof(UIElement), |
76 |
| - typeof(SplitView), |
77 |
| - new PropertyMetadata(null)); |
78 |
| - |
79 |
| - /// <summary> |
80 |
| - /// Gets or sets the contents of the main panel of a <see cref="SplitView" />. |
81 |
| - /// </summary> |
82 |
| - /// <returns>The contents of the main panel of a <see cref="SplitView" />. The default is null.</returns> |
83 |
| - public UIElement? Content |
84 |
| - { |
85 |
| - get => (UIElement?)this.GetValue(ContentProperty); |
86 |
| - set => this.SetValue(ContentProperty, value); |
87 |
| - } |
88 |
| - |
89 | 73 | /// <summary>Identifies the <see cref="DisplayMode"/> dependency property.</summary>
|
90 | 74 | public static readonly DependencyProperty DisplayModeProperty
|
91 | 75 | = DependencyProperty.Register(nameof(DisplayMode),
|
@@ -337,20 +321,87 @@ public Style? ResizeThumbStyle
|
337 | 321 | /// <summary>Identifies the <see cref="Pane"/> dependency property.</summary>
|
338 | 322 | public static readonly DependencyProperty PaneProperty
|
339 | 323 | = DependencyProperty.Register(nameof(Pane),
|
340 |
| - typeof(UIElement), |
| 324 | + typeof(object), |
341 | 325 | typeof(SplitView),
|
342 |
| - new PropertyMetadata(null, UpdateLogicalChild)); |
| 326 | + new FrameworkPropertyMetadata( |
| 327 | + null, |
| 328 | + new PropertyChangedCallback(OnPaneChanged))); |
343 | 329 |
|
344 | 330 | /// <summary>
|
345 | 331 | /// Gets or sets the contents of the pane of a <see cref="SplitView" />.
|
346 | 332 | /// </summary>
|
347 | 333 | /// <returns>The contents of the pane of a <see cref="SplitView" />. The default is null.</returns>
|
348 |
| - public UIElement? Pane |
| 334 | + [Bindable(true), Category("Content")] |
| 335 | + public object? Pane |
349 | 336 | {
|
350 |
| - get => (UIElement?)this.GetValue(PaneProperty); |
| 337 | + get => this.GetValue(PaneProperty); |
351 | 338 | set => this.SetValue(PaneProperty, value);
|
352 | 339 | }
|
353 | 340 |
|
| 341 | + /// <summary> |
| 342 | + /// Called when PaneProperty is invalidated |
| 343 | + /// </summary> |
| 344 | + private static void OnPaneChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 345 | + { |
| 346 | + SplitView splitView = (SplitView)d; |
| 347 | + |
| 348 | + splitView.OnPaneChanged(e.OldValue, e.NewValue); |
| 349 | + } |
| 350 | + |
| 351 | + /// <summary> |
| 352 | + /// This method is invoked when the Header property changes. |
| 353 | + /// </summary> |
| 354 | + /// <param name="oldPane">The old value of the Header property.</param> |
| 355 | + /// <param name="newPane">The new value of the Header property.</param> |
| 356 | + protected virtual void OnPaneChanged(object oldPane, object newPane) |
| 357 | + { |
| 358 | + this.RemoveLogicalChild(oldPane); |
| 359 | + this.AddLogicalChild(newPane); |
| 360 | + |
| 361 | + if (newPane is FrameworkElement frameworkElement) |
| 362 | + { |
| 363 | + frameworkElement.DataContext = this.DataContext; |
| 364 | + } |
| 365 | + } |
| 366 | + |
| 367 | + /// <summary>Identifies the <see cref="PaneTemplate"/> dependency property.</summary> |
| 368 | + public static readonly DependencyProperty PaneTemplateProperty |
| 369 | + = DependencyProperty.Register( |
| 370 | + nameof(PaneTemplate), |
| 371 | + typeof(DataTemplate), |
| 372 | + typeof(SplitView), |
| 373 | + new FrameworkPropertyMetadata( |
| 374 | + null, |
| 375 | + new PropertyChangedCallback(OnPaneTemplateChanged))); |
| 376 | + |
| 377 | + /// <summary> |
| 378 | + /// PaneTemplate is the template used to display the <seealso cref="Pane"/>. |
| 379 | + /// </summary> |
| 380 | + [Bindable(true), Category("Content")] |
| 381 | + public DataTemplate? PaneTemplate |
| 382 | + { |
| 383 | + get => (DataTemplate?)this.GetValue(PaneTemplateProperty); |
| 384 | + set => this.SetValue(PaneTemplateProperty, value); |
| 385 | + } |
| 386 | + |
| 387 | + /// <summary> |
| 388 | + /// Called when PaneTemplateProperty is invalidated on "d." |
| 389 | + /// </summary> |
| 390 | + private static void OnPaneTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 391 | + { |
| 392 | + SplitView ctrl = (SplitView)d; |
| 393 | + ctrl.OnPaneTemplateChanged((DataTemplate?)e.OldValue, (DataTemplate?)e.NewValue); |
| 394 | + } |
| 395 | + |
| 396 | + /// <summary> |
| 397 | + /// This method is invoked when the PaneTemplate property changes. |
| 398 | + /// </summary> |
| 399 | + /// <param name="oldPaneTemplate">The old value of the PaneTemplate property.</param> |
| 400 | + /// <param name="newPaneTemplate">The new value of the PaneTemplate property.</param> |
| 401 | + protected virtual void OnPaneTemplateChanged(DataTemplate? oldPaneTemplate, DataTemplate? newPaneTemplate) |
| 402 | + { |
| 403 | + } |
| 404 | + |
354 | 405 | /// <summary>Identifies the <see cref="PaneBackground"/> dependency property.</summary>
|
355 | 406 | public static readonly DependencyProperty PaneBackgroundProperty
|
356 | 407 | = DependencyProperty.Register(nameof(PaneBackground),
|
@@ -504,25 +555,6 @@ private void ResizingThumb_DragDelta(object sender, System.Windows.Controls.Prim
|
504 | 555 | this.SetCurrentValue(OpenPaneLengthProperty, this.PanePlacement == SplitViewPanePlacement.Left ? this.OpenPaneLength + e.HorizontalChange : this.OpenPaneLength - e.HorizontalChange);
|
505 | 556 | }
|
506 | 557 |
|
507 |
| - private static void UpdateLogicalChild(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) |
508 |
| - { |
509 |
| - if (dependencyObject is not SplitView splitView) |
510 |
| - { |
511 |
| - return; |
512 |
| - } |
513 |
| - |
514 |
| - if (e.OldValue is FrameworkElement oldChild) |
515 |
| - { |
516 |
| - splitView.RemoveLogicalChild(oldChild); |
517 |
| - } |
518 |
| - |
519 |
| - if (e.NewValue is FrameworkElement newChild) |
520 |
| - { |
521 |
| - splitView.AddLogicalChild(newChild); |
522 |
| - newChild.DataContext = splitView.DataContext; |
523 |
| - } |
524 |
| - } |
525 |
| - |
526 | 558 | /// <inheritdoc />
|
527 | 559 | protected override IEnumerator LogicalChildren
|
528 | 560 | {
|
|
0 commit comments