ActivateCommandLayoutItemFromLayoutModelConverter.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*************************************************************************************
  2. Extended WPF Toolkit
  3. Copyright (C) 2007-2013 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features, controls, and fast professional support,
  7. pick up the Plus Edition at http://xceed.com/wpf_toolkit
  8. Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
  9. ***********************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Windows.Data;
  15. using Xceed.Wpf.AvalonDock.Layout;
  16. namespace Xceed.Wpf.AvalonDock.Converters
  17. {
  18. public class ActivateCommandLayoutItemFromLayoutModelConverter : IValueConverter
  19. {
  20. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  21. {
  22. //when this converter is called layout could be constructing so many properties here are potentially not valid
  23. var layoutModel = value as LayoutContent;
  24. if (layoutModel == null)
  25. return null;
  26. if (layoutModel.Root == null)
  27. return null;
  28. if (layoutModel.Root.Manager == null)
  29. return null;
  30. var layoutItemModel = layoutModel.Root.Manager.GetLayoutItemFromModel(layoutModel);
  31. if (layoutItemModel == null)
  32. return Binding.DoNothing;
  33. return layoutItemModel.ActivateCommand;
  34. }
  35. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  36. {
  37. throw new NotImplementedException();
  38. }
  39. }
  40. }