Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Car
- {
- public string Make { get; set; }
- public Car(string make)
- {
- Make = make;
- }
- }
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto" />
- </Grid.RowDefinitions>
- <ComboBox SelectedItem="{Binding MyCar}" ItemsSource="{Binding MyCars}" DisplayMemberPath="Make" />
- </Grid>
- public partial class MainWindow : Window, INotifyPropertyChanged
- {
- private Car myCar = null;
- public List<Car> MyCars { get; set; }
- public Car MyCar
- {
- get { return myCar; }
- set
- {
- if (myCar != value)
- {
- myCar = value;
- OnPropertyChanged("MyCar");
- }
- }
- }
- public MainWindow()
- {
- MyCar = null;
- MyCars = new List<Car>();
- MyCars.Add(null);
- MyCars.Add(new Car("Ford"));
- MyCars.Add(new Car("Chevy"));
- MyCars.Add(new Car("Toyota"));
- InitializeComponent();
- }
- #region INotifyPropertyChanged
- /// <summary>
- /// Occurs when a property value changes.
- /// </summary>
- public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
- /// <summary>
- /// This function is used to raise an PropertyChanged event.
- /// </summary>
- /// <param name="prop">The name of the property whose value changed.</param>
- internal void OnPropertyChanged(string prop)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(prop));
- }
- }
- #endregion
- }
- Public Overrides Function ToString() As String
- If string.isnullorwhitespace(Make) then
- return "no Car"
- else
- return make
- end if
- End Function
- private string[] Logo_menu_array = { "Assets/star-6-48.ico", "/Assets/note-48.ico", "/Assets/medal-48.ico", "/Assets/joystick-48.ico" };
- private string[] Text_menu_array={"Phổ biến trên YouTuBe","Âm nhạc","Thể thao","Trò chơi"};
- public class listboxitem
- {
- public string textmenu { get; set; }
- public string logomenu { get; set; }
- }
- public List<listboxitem> Load_Menu()
- {
- List<listboxitem> text = new List<listboxitem>();
- for (int i = 0; i < Math.Min(Logo_menu_array.Length, Text_menu_array.Length); i++)
- {
- var l = new listboxitem();
- l.logomenu = Logo_menu_array[i];
- l.textmenu = Text_menu_array[i];
- text.Add(l);
- }
- return text;
- }
- public MainPage()
- {
- this.InitializeComponent();
- //get menu
- List<listboxitem> menu_list = Load_Menu();
- lst_menu.ItemsSource = menu_list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement