|
11 | 11 | namespace MahApps.Metro.Controls
|
12 | 12 | {
|
13 | 13 | [StyleTypedProperty(Property = "ItemContainerStyle", StyleTargetType = typeof(WindowCommands))]
|
14 |
| - public class WindowCommands : ItemsControl, INotifyPropertyChanged |
| 14 | + public class WindowCommands : ToolBar, INotifyPropertyChanged |
15 | 15 | {
|
16 | 16 | public static readonly DependencyProperty ThemeProperty =
|
17 | 17 | DependencyProperty.Register("Theme", typeof(Theme), typeof(WindowCommands),
|
@@ -270,6 +270,13 @@ private IEnumerable<WindowCommandsItem> GetWindowCommandsItems()
|
270 | 270 | private void WindowCommands_Loaded(object sender, RoutedEventArgs e)
|
271 | 271 | {
|
272 | 272 | this.Loaded -= WindowCommands_Loaded;
|
| 273 | + |
| 274 | + var contentPresenter = this.TryFindParent<ContentPresenter>(); |
| 275 | + if (contentPresenter != null) |
| 276 | + { |
| 277 | + this.SetCurrentValue(DockPanel.DockProperty, contentPresenter.GetValue(DockPanel.DockProperty)); |
| 278 | + } |
| 279 | + |
273 | 280 | var parentWindow = this.ParentWindow;
|
274 | 281 | if (null == parentWindow)
|
275 | 282 | {
|
@@ -312,21 +319,48 @@ public class WindowCommandsItem : ContentControl
|
312 | 319 | internal PropertyChangeNotifier VisibilityPropertyChangeNotifier { get; set; }
|
313 | 320 |
|
314 | 321 | public static readonly DependencyProperty IsSeparatorVisibleProperty =
|
315 |
| - DependencyProperty.Register("IsSeparatorVisible", typeof(bool), typeof(WindowCommandsItem), |
316 |
| - new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.Inherits|FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); |
| 322 | + DependencyProperty.Register( |
| 323 | + nameof(IsSeparatorVisible), |
| 324 | + typeof(bool), |
| 325 | + typeof(WindowCommandsItem), |
| 326 | + new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); |
317 | 327 |
|
318 | 328 | /// <summary>
|
319 | 329 | /// Gets or sets the value indicating whether to show the separator.
|
320 | 330 | /// </summary>
|
321 | 331 | public bool IsSeparatorVisible
|
322 | 332 | {
|
323 |
| - get { return (bool)GetValue(IsSeparatorVisibleProperty); } |
324 |
| - set { SetValue(IsSeparatorVisibleProperty, value); } |
| 333 | + get { return (bool)this.GetValue(IsSeparatorVisibleProperty); } |
| 334 | + set { this.SetValue(IsSeparatorVisibleProperty, value); } |
| 335 | + } |
| 336 | + |
| 337 | + public static readonly DependencyPropertyKey ParentWindowCommandsPropertyKey = |
| 338 | + DependencyProperty.RegisterReadOnly( |
| 339 | + nameof(ParentWindowCommands), |
| 340 | + typeof(WindowCommands), |
| 341 | + typeof(WindowCommandsItem), |
| 342 | + new PropertyMetadata(null)); |
| 343 | + |
| 344 | + public static readonly DependencyProperty ParentWindowCommandsProperty = ParentWindowCommandsPropertyKey.DependencyProperty; |
| 345 | + |
| 346 | + public WindowCommands ParentWindowCommands |
| 347 | + { |
| 348 | + get { return (WindowCommands)this.GetValue(ParentWindowCommandsProperty); } |
| 349 | + private set { this.SetValue(ParentWindowCommandsPropertyKey, value); } |
325 | 350 | }
|
326 | 351 |
|
327 | 352 | static WindowCommandsItem()
|
328 | 353 | {
|
329 | 354 | DefaultStyleKeyProperty.OverrideMetadata(typeof(WindowCommandsItem), new FrameworkPropertyMetadata(typeof(WindowCommandsItem)));
|
330 | 355 | }
|
| 356 | + |
| 357 | + /// <inheritdoc /> |
| 358 | + public override void OnApplyTemplate() |
| 359 | + { |
| 360 | + base.OnApplyTemplate(); |
| 361 | + |
| 362 | + var windowCommands = ItemsControl.ItemsControlFromItemContainer(this) as WindowCommands; |
| 363 | + this.SetValue(WindowCommandsItem.ParentWindowCommandsPropertyKey, windowCommands); |
| 364 | + } |
331 | 365 | }
|
332 | 366 | }
|
0 commit comments