Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. using System.Collections.Generic;
  2.  
  3. namespace App3
  4. {
  5. public class Kontakter
  6. {
  7. public string Fuldenavn { get; set; }
  8. public int Tlfnr { get; set; }
  9. public string Email { get; set; }
  10. public string Adresse { get; set; }
  11. public string Billed { get; set; }
  12.  
  13. public List<Kontakter> GetKontakter()
  14. {
  15. List<Kontakter> kontakter = new List<Kontakter>
  16. {
  17. new Kontakter
  18. {
  19. Fuldenavn = "Anders (ANSE)",
  20. Email = "Random@gmail.com",
  21. Tlfnr = 12345678,
  22. },
  23. new Kontakter
  24. {
  25. Fuldenavn = "Anja (ANBI)",
  26. Email = "Random@hotmail.dk",
  27. Tlfnr = 87654321,
  28. },
  29. new Kontakter
  30. {
  31. Fuldenavn = "Benn (BMR)",
  32. Email = "Random@hotmail.com",
  33. Tlfnr = 12876534,
  34. },
  35. new Kontakter
  36. {
  37. Fuldenavn = "Christian (CBE)",
  38. Email = "Nothing@gmail.com",
  39. Tlfnr = 18273645,
  40. },
  41. };
  42. return kontakter;
  43. }
  44. }
  45. }
  46.  
  47. using Plugin.Messaging;
  48. using System;
  49. using System.Linq;
  50. using Xamarin.Forms;
  51.  
  52. namespace App3
  53. {
  54. public partial class MainPage : ContentPage
  55. {
  56. KontaktlisteView vm;
  57.  
  58. public MainPage()
  59. {
  60. InitializeComponent();
  61. vm = new KontaktlisteView();
  62. NameslistView.ItemsSource = vm.Kontakter;
  63. }
  64.  
  65. private async void Kontakter_ItemTapped(object sender, ItemTappedEventArgs e)
  66. {
  67. ((ListView)sender).SelectedItem = null;
  68. var Kontakter = e.Item as Kontakter;
  69.  
  70. await DisplayAlert("Kontakt", "nName: " + Kontakter.Fuldenavn + "nTelefon: " + Kontakter.Tlfnr + "nEmail: " + Kontakter.Email, "Luk");
  71. }
  72.  
  73. private void MainSearchBar_SearchButtonPressed(object sender, EventArgs e)
  74. {
  75. var keyword = MainSearchBar.Text;
  76. NameslistView.ItemsSource = vm.Kontakter.Where(obj => (obj.Fuldenavn.Contains(keyword) || obj.Tlfnr.ToString().Contains(keyword)));
  77. }
  78. private void MainSearchBar_TextChanged(object sender, TextChangedEventArgs e)
  79. {
  80. NameslistView.ItemsSource = vm.Kontakter.Where(obj => (obj.Fuldenavn.Contains(e.NewTextValue) || obj.Tlfnr.ToString().Contains(e.NewTextValue)));
  81. }
  82.  
  83. private void OnEmailTapped(object sender, EventArgs e)
  84. {
  85. var emailMessenger = CrossMessaging.Current.EmailMessenger;
  86. if (emailMessenger.CanSendEmail)
  87.  
  88. emailMessenger.SendEmail("Something@gmail.com");
  89. }
  90.  
  91. private void TlfnrTapped(object sender, EventArgs e)
  92. {
  93. var phoneDialer = CrossMessaging.Current.PhoneDialer;
  94. if (phoneDialer.CanMakePhoneCall)
  95. phoneDialer.MakePhoneCall("12345678");
  96. }
  97. }
  98. }
  99.  
  100. <?xml version="1.0" encoding="utf-8" ?>
  101. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
  102. xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  103. xmlns:local="clr-namespace:App3"
  104. x:Class="App3.MainPage">
  105.  
  106. <StackLayout>
  107. <SearchBar x:Name="MainSearchBar" Placeholder="Søg"
  108. SearchButtonPressed="MainSearchBar_SearchButtonPressed"
  109. TextChanged="MainSearchBar_TextChanged"/>
  110. <ListView x:Name="NameslistView" HasUnevenRows="True"
  111. ItemTapped="Kontakter_ItemTapped" >
  112. <ListView.ItemTemplate>
  113. <DataTemplate>
  114. <ViewCell>
  115. <StackLayout Orientation="Vertical" >
  116. <Grid HeightRequest="5" BackgroundColor="White" />
  117. <StackLayout Orientation="Horizontal" BackgroundColor="LightSkyBlue" >
  118. <Image Source="{Binding Billed}" />
  119. <StackLayout Orientation="Vertical">
  120.  
  121. <Label Text="{Binding Fuldenavn}" TextColor="Black" FontSize="Large" />
  122.  
  123. <StackLayout>
  124. <Label Text="{Binding Tlfnr}" TextColor="Black" FontSize="Medium" />
  125.  
  126. <Label.GestureRecognizers>
  127. <TapGestureRecognizer Tapped="TlfnrTapped"/>
  128. </Label.GestureRecognizers>
  129. </StackLayout>
  130.  
  131. <StackLayout>
  132. <Label Text="{Binding Email}" TextColor="Black" FontSize="Medium" />
  133.  
  134. <Label.GestureRecognizers>
  135. <TapGestureRecognizer Tapped="OnEmailTapped"/>
  136. </Label.GestureRecognizers>
  137. </StackLayout>
  138.  
  139.  
  140.  
  141. </StackLayout>
  142. </StackLayout>
  143. </StackLayout >
  144. </ViewCell>
  145. </DataTemplate>
  146. </ListView.ItemTemplate>
  147. </ListView>
  148. </StackLayout >
  149.  
  150. </ContentPage>
  151.  
  152. using System.Collections.Generic;
  153.  
  154. namespace App3
  155. {
  156. public class KontaktlisteView
  157. {
  158. public List<Kontakter> Kontakter { get; set; }
  159. public static object SelectedItem { get; internal set; }
  160.  
  161. public KontaktlisteView()
  162. {
  163. Kontakter = new Kontakter
  164. ().GetKontakter();
  165. }
  166. }
  167. }
  168.  
  169. using System;
  170. using System.Collections.Generic;
  171. using System.Linq;
  172. using System.Text;
  173.  
  174. using Xamarin.Forms;
  175.  
  176. namespace App3
  177. {
  178. public partial class App : Application
  179. {
  180. public App ()
  181. {
  182. InitializeComponent();
  183.  
  184. MainPage = new App3.MainPage();
  185. }
  186.  
  187. protected override void OnStart ()
  188. {
  189. // Handle when your app starts
  190. }
  191.  
  192. protected override void OnSleep ()
  193. {
  194. // Handle when your app sleeps
  195. }
  196.  
  197. protected override void OnResume ()
  198. {
  199. // Handle when your app resumes
  200. }
  201. }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement