Removing Tizen.Xamarin.Forms.Extensions
[profile/tv/apps/dotnet/mediahub.git] / TVMediaHub / TVMediaHub.Tizen / Extensions / ContextPopupItem.cs
1 using System.ComponentModel;
2 using System.Runtime.CompilerServices;
3 using Xamarin.Forms;
4
5 namespace Tizen.Xamarin.Forms.Extension
6 {
7     /// <summary>
8     /// The class for the items in a ContextPopup.
9     /// Each item can have a label and an icon.
10     /// </summary>
11     /// <example>
12     /// <code>
13     /// new ContextPopupItem("Text only item");
14     /// new ContextPopupItem("Home icon", "home");
15     /// new ContextPopupItem("Car", "car.png");
16     /// new ContextPopupItem("Chat", StandardIconResource.MenuChat.Name);
17     /// </code>
18     /// </example>
19     public class ContextPopupItem : INotifyPropertyChanged
20     {
21         string _label;
22         FileImageSource _icon;
23
24         /// <summary>
25         /// Creates a ContextPopupItem with only a label.
26         /// </summary>
27         /// <param name="label">The label of the ContextPopupItem.</param>
28         public ContextPopupItem(string label)
29         {
30             _label = label;
31         }
32
33         /// <summary>
34         /// Creates a ContextPopupItem with a label and an icon. The icon may be an image or a standard icon.<br>
35         /// To create a ContextPopupItem with only an icon, set the label to an empty string.<br>
36         /// The available standard icons that can be used are specified in the StandardIconResource class.
37         /// The name property of the StandardIconResource class can be used to specify a standard icon.
38         /// </summary>
39         /// <param name="label">The label of the ContextPopupItem.</param>
40         /// <param name="icon">The icon of the ContextPopupItem.</param>
41         /// <code>
42         /// new ContextPopupItem("Text only item");
43         /// new ContextPopupItem("Home icon", "home");
44         /// new ContextPopupItem("Car", "car.png");
45         /// new ContextPopupItem("Chat", StandardIconResource.MenuChat.Name);
46         /// </code>
47         public ContextPopupItem(string label, FileImageSource icon)
48         {
49             if (label == null)
50                 label = "";
51             _label = label;
52             _icon = icon;
53         }
54
55         /// <summary>
56         /// Occurs when the label or an icon of a ContextPopupItem is changed.
57         /// </summary>
58         public event PropertyChangedEventHandler PropertyChanged;
59
60         /// <summary>
61         /// Gets or sets the label of a ContextPopupItem.
62         /// </summary>
63         public string Label
64         {
65             get
66             {
67                 return _label;
68             }
69             set
70             {
71                 if (value != _label)
72                 {
73                     _label = value;
74                     OnPropertyChanged();
75                 }
76             }
77         }
78
79         /// <summary>
80         /// Gets or sets the icon of a ContextPopupItem. The icon may be an image or a standard icon.<br>
81         /// The available standard icons that can be used are specified in the StandardIconResource class.
82         /// The name property of the StandardIconResource class can be used to specify a standard icon.
83         /// </summary>
84         /// <remarks>
85         /// Icon is only supported on the mobile profile.
86         /// Icon does not always work as expected on the TV profile.
87         /// </remarks>
88         public FileImageSource Icon
89         {
90             get
91             {
92                 return _icon;
93             }
94             set
95             {
96                 if (value != _icon)
97                 {
98                     _icon = value;
99                     OnPropertyChanged();
100                 }
101             }
102         }
103
104         /// <summary>
105         /// Called when a bindable property has changed.
106         /// </summary>
107         protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
108         {
109             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
110         }
111     }
112 }