Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class MainWindow : Window
- {
- private List<Person> people = new List<Person>();
- public MainWindow()
- {
- InitializeComponent();
- people.Add(new Person { Firstname = "Sinead", Lastname = "McCoy" , Sex = "Female" });
- people.Add(new Person { Firstname = "Andrew", Lastname = "Warner", Sex = "Other" });
- people.Add(new Person { Firstname = "Ailish", Lastname = "Man" , Sex = "Female" });
- people.Add(new Person { Firstname = "Andrew", Lastname = "McCory", Sex = "Other" });
- people.Add(new Person { Firstname = "Andrew", Lastname = "McCall" , Sex = "Male" });
- //people.Add(a);
- cmbMyComboBox.ItemsSource = people;
- }
- class Person
- {
- private string _sex;
- private string _cmbimage;
- public string Firstname { get; set; }
- public string Lastname { get; set; }
- public string Sex
- {
- get
- {
- var sex = new string[] { "Male", "Female" };
- if (sex.Contains(_sex))
- {
- return _sex;
- }
- else
- _sex = "Other";
- return _sex;
- }
- set
- {
- _sex = value;
- }
- }
- public string Fullname
- {
- get
- {
- return $"{Firstname} {Lastname}";
- }
- }
- public string Cmbimage
- {
- get
- {
- if (_sex == "Male")
- {
- _cmbimage = "C:\Users\richa\Pictures\Icons\WPFdemo\cmbimage.png";
- return _cmbimage;
- }
- if (_sex == "Female")
- {
- _cmbimage = "C:\Users\richa\Pictures\Icons\WPFdemo\cmbimagegirl.png";
- return _cmbimage;
- }
- else
- _cmbimage = "C:\Users\richa\Pictures\Icons\WPFdemo\cmbimageother.png";
- return _cmbimage;
- }
- }
- }
- <ComboBox x:Name="cmbMyComboBox" Grid.Column="1"
- Grid.Row="3" Grid.ColumnSpan="2" Margin="10">
- <ComboBox.ItemTemplate>
- <DataTemplate>
- <StackPanel Orientation="Horizontal">
- <Image Source="{Binding Cmbimage}" Height="20" Width="20"/>
- <TextBlock Text="{Binding Fullname}"/>
- <!--<TextBlock Text=" "/>
- <TextBlock Text="{Binding Lastname}"/>
- <TextBlock Text=" "/>
- <TextBlock Text="{Binding Sex}"/>-->
- </StackPanel>
- </DataTemplate>
- </ComboBox.ItemTemplate>
- </ComboBox>
Add Comment
Please, Sign In to add comment