Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. public class Car
  2. {
  3. public string Make { get; set; }
  4.  
  5. public Car(string make)
  6. {
  7. Make = make;
  8. }
  9.  
  10. }
  11.  
  12. <Grid>
  13. <Grid.RowDefinitions>
  14. <RowDefinition Height="Auto" />
  15. </Grid.RowDefinitions>
  16. <ComboBox SelectedItem="{Binding MyCar}" ItemsSource="{Binding MyCars}" DisplayMemberPath="Make" />
  17. </Grid>
  18.  
  19. public partial class MainWindow : Window, INotifyPropertyChanged
  20. {
  21. private Car myCar = null;
  22.  
  23. public List<Car> MyCars { get; set; }
  24.  
  25. public Car MyCar
  26. {
  27. get { return myCar; }
  28. set
  29. {
  30. if (myCar != value)
  31. {
  32. myCar = value;
  33. OnPropertyChanged("MyCar");
  34. }
  35. }
  36. }
  37.  
  38.  
  39. public MainWindow()
  40. {
  41. MyCar = null;
  42.  
  43. MyCars = new List<Car>();
  44. MyCars.Add(null);
  45. MyCars.Add(new Car("Ford"));
  46. MyCars.Add(new Car("Chevy"));
  47. MyCars.Add(new Car("Toyota"));
  48.  
  49. InitializeComponent();
  50.  
  51. }
  52.  
  53.  
  54. #region INotifyPropertyChanged
  55. /// <summary>
  56. /// Occurs when a property value changes.
  57. /// </summary>
  58. public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
  59.  
  60. /// <summary>
  61. /// This function is used to raise an PropertyChanged event.
  62. /// </summary>
  63. /// <param name="prop">The name of the property whose value changed.</param>
  64. internal void OnPropertyChanged(string prop)
  65. {
  66. if (PropertyChanged != null)
  67. {
  68. PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(prop));
  69. }
  70. }
  71. #endregion
  72.  
  73. }
  74.  
  75. Public Overrides Function ToString() As String
  76. If string.isnullorwhitespace(Make) then
  77. return "no Car"
  78. else
  79. return make
  80. end if
  81. End Function
  82.  
  83. private string[] Logo_menu_array = { "Assets/star-6-48.ico", "/Assets/note-48.ico", "/Assets/medal-48.ico", "/Assets/joystick-48.ico" };
  84. private string[] Text_menu_array={"Phổ biến trên YouTuBe","Âm nhạc","Thể thao","Trò chơi"};
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. public class listboxitem
  92. {
  93. public string textmenu { get; set; }
  94. public string logomenu { get; set; }
  95. }
  96.  
  97.  
  98.  
  99. public List<listboxitem> Load_Menu()
  100. {
  101. List<listboxitem> text = new List<listboxitem>();
  102. for (int i = 0; i < Math.Min(Logo_menu_array.Length, Text_menu_array.Length); i++)
  103. {
  104. var l = new listboxitem();
  105. l.logomenu = Logo_menu_array[i];
  106. l.textmenu = Text_menu_array[i];
  107. text.Add(l);
  108. }
  109.  
  110. return text;
  111. }
  112.  
  113. public MainPage()
  114. {
  115. this.InitializeComponent();
  116. //get menu
  117. List<listboxitem> menu_list = Load_Menu();
  118. lst_menu.ItemsSource = menu_list;
  119.  
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement