PageRenderTime 66ms CodeModel.GetById 40ms RepoModel.GetById 0ms app.codeStats 0ms

/Signum.Windows/Widgets/LinksWidget.xaml.cs

https://github.com/mutharasank/framework
C# | 67 lines | 56 code | 8 blank | 3 comment | 7 complexity | b26320541004790dd41002005fc96bea MD5 | raw file
Possible License(s): GPL-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Signum.Utilities;
  15. using Signum.Entities.DynamicQuery;
  16. using Signum.Entities;
  17. using System.ComponentModel;
  18. using System.Collections.ObjectModel;
  19. using System.Reflection;
  20. using System.Windows.Automation;
  21. namespace Signum.Windows
  22. {
  23. /// <summary>
  24. /// Interaction logic for LinksWidget.xaml
  25. /// </summary>
  26. public partial class LinksWidget : UserControl, IWidget
  27. {
  28. public Control Control { get; set; }
  29. public event Action ForceShow;
  30. public LinksWidget()
  31. {
  32. InitializeComponent();
  33. this.AddHandler(Button.ClickEvent, new RoutedEventHandler(QuickLink_MouseDown));
  34. this.DataContextChanged += new DependencyPropertyChangedEventHandler(LinksWidget_DataContextChanged);
  35. }
  36. void LinksWidget_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
  37. {
  38. IdentifiableEntity ident = e.NewValue as IdentifiableEntity;
  39. ObservableCollection<QuickLink> links = ident != null && !ident.IsNew ? LinksClient.GetForEntity(ident.ToLiteFat(), Control) : new ObservableCollection<QuickLink>();
  40. lvQuickLinks.ItemsSource = links;
  41. if (links.IsNullOrEmpty())
  42. Visibility = Visibility.Collapsed;
  43. else
  44. {
  45. Visibility = Visibility.Visible;
  46. if (ForceShow != null && links.Any(a => !a.IsShy))
  47. ForceShow();
  48. }
  49. }
  50. private void QuickLink_MouseDown(object sender, RoutedEventArgs e)
  51. {
  52. if (e.OriginalSource is Button) //Not to capture the mouseDown of the scrollbar buttons
  53. {
  54. Button b = (Button)e.OriginalSource;
  55. ((QuickLink)b.DataContext).Execute();
  56. }
  57. }
  58. }
  59. }