WindowViewModel.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using AvalonDock.Layout;
  2. using GalaSoft.MvvmLight.CommandWpf;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace PixiEditor.ViewModels.SubViewModels.Main
  6. {
  7. public class WindowViewModel : SubViewModel<ViewModelMain>, ISettableOwner<ViewModelMain>
  8. {
  9. public RelayCommand<string> ShowAvalonDockWindowCommand { get; set; }
  10. public WindowViewModel()
  11. : this(null)
  12. {
  13. }
  14. public WindowViewModel(ViewModelMain owner)
  15. : base(owner)
  16. {
  17. ShowAvalonDockWindowCommand = new(ShowAvalonDockWindow);
  18. }
  19. public void SetOwner(ViewModelMain owner)
  20. {
  21. Owner = owner;
  22. }
  23. private void ShowAvalonDockWindow(string id)
  24. {
  25. var anchorables = new List<LayoutAnchorable>(MainWindow.Current.LayoutRoot.Manager.Layout
  26. .Descendents()
  27. .OfType<LayoutAnchorable>());
  28. foreach (var la in anchorables)
  29. {
  30. if (la.ContentId == id)
  31. {
  32. la.Show();
  33. la.IsActive = true;
  34. }
  35. }
  36. }
  37. }
  38. }