Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. <ComboBox ItemsSource="{Binding AllCustomers}" IsEditable="True"/>
  2.  
  3. <ComboBox ItemsSource="{Binding AllCustomers}" DisplayMemberPath="CustomerName" IsEditable="True"/>
  4.  
  5. <ComboBox ItemsSource="{Binding AllCustomers}" SelectedValue="CustomerName" IsEditable="True">
  6. <ItemsControl.ItemTemplate>
  7. <DataTemplate>
  8. <TextBlock Text="{Binding CustomerName}"/>
  9. </DataTemplate>
  10. </ItemsControl.ItemTemplate>
  11. </ComboBox>
  12.  
  13. public class AllCustomersViewModel
  14. {
  15. public ObservableCollection<CustomerViewModel> AllCustomers {get; set;}
  16. }
  17.  
  18. public class CustomerViewModel
  19. {
  20. public string CustomerName;
  21. public short CustomerID;
  22. }
  23.  
  24. public class AccountTransactionsViewModel
  25. {
  26. DataRepository _repository;
  27.  
  28. public AccountTransactionsViewModel()
  29. {
  30. _repository = new DataRepository();
  31. CreateAccountsViewModel();
  32. }
  33.  
  34. public ObservableCollection<AccountViewModel> AllAccounts { get; set; }
  35.  
  36. void CreateAccountsViewModel()
  37. {
  38. List<AccountViewModel> allAccounts = _repository.GetAccounts()
  39. .Select(a => new AccountViewModel(a, _repository))
  40. .ToList();
  41.  
  42. AllAccounts = new ObservableCollection<AccountViewModel>(allAccounts);
  43. }
  44. }
  45.  
  46.  
  47.  
  48. public class AccountViewModel
  49. {
  50. Account _account;
  51. DataRepository _repository;
  52.  
  53. public AccountViewModel(Account account, DataRepository repository)
  54. {
  55. _account = account;
  56. _repository = repository;
  57. }
  58.  
  59. public short AccountID { get { return _account.AccountID; } set { } }
  60. public string AccountName { get { return _account.AccountName; } set { } }
  61. }
  62.  
  63. <ComboBox Name="customerCombobox" ItemsSource="{Binding AllAccounts}" IsEditable="True">
  64. <ItemsControl.ItemTemplate>
  65. <DataTemplate>
  66. <TextBlock Text="{Binding AccountName}"/>
  67. </DataTemplate>
  68. </ItemsControl.ItemTemplate>
  69. </ComboBox>
  70.  
  71. <ComboBox ItemsSource="{Binding AllCustomers}" SelectedValue="CustomerName">
  72. <ItemsControl.ItemTemplate>
  73. <DataTemplate>
  74. <TextBlock Text="{Binding Item.CustomerName}"/>
  75. </DataTemplate>
  76. </ItemsControl.ItemTemplate>
  77. </ComboBox>
  78.  
  79. <ComboBox Name="customerCombobox" ItemsSource="{Binding AllAccounts}" SelectedValuePath="AccountName">
  80. <ItemsControl.ItemTemplate>
  81. <DataTemplate>
  82. <TextBlock Text="{Binding AccountName}"/>
  83. </DataTemplate>
  84. </ItemsControl.ItemTemplate>
  85. </ComboBox>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement