ExtendedImage.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Media;
  4. namespace MediaBrowser.UI.Controls
  5. {
  6. /// <summary>
  7. /// Follow steps 1a or 1b and then 2 to use this custom control in a XAML file.
  8. ///
  9. /// Step 1a) Using this custom control in a XAML file that exists in the current project.
  10. /// Add this XmlNamespace attribute to the root element of the markup file where it is
  11. /// to be used:
  12. ///
  13. /// xmlns:MyNamespace="clr-namespace:MediaBrowser.UI.Controls"
  14. ///
  15. ///
  16. /// Step 1b) Using this custom control in a XAML file that exists in a different project.
  17. /// Add this XmlNamespace attribute to the root element of the markup file where it is
  18. /// to be used:
  19. ///
  20. /// xmlns:MyNamespace="clr-namespace:MediaBrowser.UI.Controls;assembly=MediaBrowser.UI.Controls"
  21. ///
  22. /// You will also need to add a project reference from the project where the XAML file lives
  23. /// to this project and Rebuild to avoid compilation errors:
  24. ///
  25. /// Right click on the target project in the Solution Explorer and
  26. /// "Add Reference"->"Projects"->[Browse to and select this project]
  27. ///
  28. ///
  29. /// Step 2)
  30. /// Go ahead and use your control in the XAML file.
  31. ///
  32. /// <MyNamespace:ExtendedImage/>
  33. ///
  34. /// </summary>
  35. public class ExtendedImage : Control
  36. {
  37. public static readonly DependencyProperty HasImageProperty = DependencyProperty.Register(
  38. "HasImage",
  39. typeof (bool),
  40. typeof (ExtendedImage),
  41. new PropertyMetadata(default(bool)));
  42. public bool HasImage
  43. {
  44. get { return (bool)GetValue(HasImageProperty); }
  45. set { SetValue(HasImageProperty, value); }
  46. }
  47. public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
  48. "Source",
  49. typeof(ImageSource),
  50. typeof(ExtendedImage),
  51. new PropertyMetadata(default(ImageBrush)));
  52. public ImageSource Source
  53. {
  54. get { return (ImageSource)GetValue(SourceProperty); }
  55. set { SetValue(SourceProperty, value); }
  56. }
  57. public static readonly DependencyProperty StretchProperty = DependencyProperty.Register(
  58. "Stretch",
  59. typeof (Stretch),
  60. typeof (ExtendedImage),
  61. new PropertyMetadata(default(Stretch)));
  62. public Stretch Stretch
  63. {
  64. get { return (Stretch) GetValue(StretchProperty); }
  65. set { SetValue(StretchProperty, value); }
  66. }
  67. public static readonly DependencyProperty PlaceHolderSourceProperty = DependencyProperty.Register(
  68. "PlaceHolderSource",
  69. typeof(ImageSource),
  70. typeof(ExtendedImage),
  71. new PropertyMetadata(default(ImageBrush)));
  72. public ImageSource PlaceHolderSource
  73. {
  74. get { return (ImageSource)GetValue(PlaceHolderSourceProperty); }
  75. set { SetValue(PlaceHolderSourceProperty, value); }
  76. }
  77. static ExtendedImage()
  78. {
  79. DefaultStyleKeyProperty.OverrideMetadata(typeof(ExtendedImage),
  80. new FrameworkPropertyMetadata(typeof(ExtendedImage)));
  81. }
  82. }
  83. }