Guest User

Untitled

a guest
Feb 17th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. public partial class MainWindow : Window
  2. {
  3. private List<Person> people = new List<Person>();
  4.  
  5. public MainWindow()
  6. {
  7. InitializeComponent();
  8. people.Add(new Person { Firstname = "Sinead", Lastname = "McCoy" , Sex = "Female" });
  9. people.Add(new Person { Firstname = "Andrew", Lastname = "Warner", Sex = "Other" });
  10. people.Add(new Person { Firstname = "Ailish", Lastname = "Man" , Sex = "Female" });
  11. people.Add(new Person { Firstname = "Andrew", Lastname = "McCory", Sex = "Other" });
  12. people.Add(new Person { Firstname = "Andrew", Lastname = "McCall" , Sex = "Male" });
  13.  
  14.  
  15. //people.Add(a);
  16. cmbMyComboBox.ItemsSource = people;
  17.  
  18. }
  19.  
  20. class Person
  21. {
  22. private string _sex;
  23. private string _cmbimage;
  24. public string Firstname { get; set; }
  25. public string Lastname { get; set; }
  26. public string Sex
  27. {
  28. get
  29. {
  30. var sex = new string[] { "Male", "Female" };
  31.  
  32. if (sex.Contains(_sex))
  33. {
  34. return _sex;
  35. }
  36. else
  37. _sex = "Other";
  38. return _sex;
  39. }
  40.  
  41. set
  42. {
  43. _sex = value;
  44. }
  45. }
  46.  
  47. public string Fullname
  48. {
  49. get
  50. {
  51. return $"{Firstname} {Lastname}";
  52. }
  53.  
  54. }
  55.  
  56. public string Cmbimage
  57. {
  58. get
  59. {
  60. if (_sex == "Male")
  61. {
  62. _cmbimage = "C:\Users\richa\Pictures\Icons\WPFdemo\cmbimage.png";
  63. return _cmbimage;
  64. }
  65. if (_sex == "Female")
  66. {
  67. _cmbimage = "C:\Users\richa\Pictures\Icons\WPFdemo\cmbimagegirl.png";
  68. return _cmbimage;
  69. }
  70. else
  71. _cmbimage = "C:\Users\richa\Pictures\Icons\WPFdemo\cmbimageother.png";
  72. return _cmbimage;
  73. }
  74. }
  75.  
  76. }
  77.  
  78. <ComboBox x:Name="cmbMyComboBox" Grid.Column="1"
  79. Grid.Row="3" Grid.ColumnSpan="2" Margin="10">
  80. <ComboBox.ItemTemplate>
  81. <DataTemplate>
  82. <StackPanel Orientation="Horizontal">
  83. <Image Source="{Binding Cmbimage}" Height="20" Width="20"/>
  84. <TextBlock Text="{Binding Fullname}"/>
  85. <!--<TextBlock Text=" "/>
  86. <TextBlock Text="{Binding Lastname}"/>
  87. <TextBlock Text=" "/>
  88. <TextBlock Text="{Binding Sex}"/>-->
  89. </StackPanel>
  90. </DataTemplate>
  91. </ComboBox.ItemTemplate>
  92. </ComboBox>
Add Comment
Please, Sign In to add comment