Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. <view:CustomTabControl ItemsSource="{Binding OpenTabs}" Grid.Column="1" x:Name="Tabs">
  2. <view:CustomTabControl.Resources>
  3. <DataTemplate DataType="{x:Type model:Tennant}">
  4. <ScrollViewer>
  5. <Grid>
  6. <TextBlock Text="{Binding name}"/>
  7. </Grid>
  8. </ScrollViewer>
  9. </DataTemplate>
  10. <DataTemplate DataType="{x:Type model:Property}">
  11. <ScrollViewer>
  12. <Grid MinWidth="350">
  13. <!-- All of the stuff that works for the Property layout in here -->
  14. </Grid>
  15. </ScrollViewer>
  16. </DataTemplate>
  17. </view:CustomTabControl.Resources>
  18. </view:CustomTabControl>
  19.  
  20. <ScrollViewer VerticalScrollBarVisibility="Auto">
  21. <StackPanel>
  22. <TextBlock Margin="10,5" Text="Properties" FontSize="16"/>
  23. <ListBox x:Name="propertiesList" ItemsSource="{Binding Properties, Mode=TwoWay}">
  24. <ListBox.ItemTemplate>
  25. <DataTemplate DataType="{x:Type model:Property}">
  26. <TextBlock Text="{Binding title}"/>
  27. </DataTemplate>
  28. </ListBox.ItemTemplate>
  29. </ListBox>
  30. <TextBlock Margin="10,5" Text="Tennants" FontSize="16"/>
  31. <ListBox x:Name="tennantsList" ItemsSource="{Binding Tennants, Mode=TwoWay}">
  32. <ListBox.ItemTemplate>
  33. <DataTemplate DataType="{x:Type model:Tennant}">
  34. <TextBlock Text="{Binding name}"/>
  35. </DataTemplate>
  36. </ListBox.ItemTemplate>
  37. </ListBox>
  38. </StackPanel>
  39. </ScrollViewer>
  40.  
  41. [Serializable]
  42. public class Tennant : ISerializable, INotifyPropertyChanged
  43. {
  44. public event PropertyChangedEventHandler PropertyChanged;
  45.  
  46. private bool current;
  47. private string name;
  48. private string phone;
  49. private string email;
  50. private string occupation;
  51. public bool Current { get { return current; } set { current = value; OnPropertyChanged("Current"); } }
  52. public string Name { get { return name; } set { name = value; OnPropertyChanged("Name"); } }
  53. public string Phone { get { return phone; } set { phone = value; OnPropertyChanged("Phone"); } }
  54. public string Email { get { return email; } set { email = value; OnPropertyChanged("Email"); } }
  55. public string Occupation { get { return occupation; } set { occupation = value; OnPropertyChanged("Occupation"); } }
  56.  
  57. public Tennant()
  58. {
  59.  
  60. }
  61.  
  62. public Tennant(bool current, string name, string phone, string email, string occupation)
  63. {
  64. this.Current = current;
  65. this.Name = name;
  66. this.Phone = phone;
  67. this.Email = email;
  68. this.Occupation = occupation;
  69. }
  70.  
  71. private void OnPropertyChanged(string p)
  72. {
  73. if (PropertyChanged != null)
  74. {
  75. PropertyChanged(this, new PropertyChangedEventArgs(p));
  76. }
  77. }
  78.  
  79. public override string ToString()
  80. {
  81. return "" + Current + " " + Name + " " + Phone + " " + Email + " " + Occupation;
  82. }
  83.  
  84. public Tennant(SerializationInfo info, StreamingContext context)
  85. {
  86. this.Current = (bool)info.GetValue("Current", typeof(bool));
  87. this.Name = (string)info.GetValue("Name", typeof(string));
  88. this.Phone = (string)info.GetValue("Phone", typeof(string));
  89. this.Email = (string)info.GetValue("Email", typeof(string));
  90. this.Occupation = (string)info.GetValue("Occupation", typeof(string));
  91.  
  92. }
  93.  
  94. public void GetObjectData(SerializationInfo info, StreamingContext context)
  95. {
  96. info.AddValue("Current", this.Current);
  97. info.AddValue("Name", this.Name);
  98. info.AddValue("Phone", this.Phone);
  99. info.AddValue("Email", this.Email);
  100. info.AddValue("Occupation", this.Occupation);
  101. }
  102. }
  103.  
  104. public class Property : ISerializable
  105. {
  106. public string address { get; set; }
  107. public string city { get; set; }
  108. public string postcode { get; set; }
  109. // ...
  110.  
  111. public Property()
  112. {
  113. // ...
  114. }
  115.  
  116. public string toString()
  117. {
  118. return title;
  119. }
  120.  
  121. public bool hasPhotos()
  122. {
  123. return false;
  124. }
  125.  
  126. public bool hasTennant()
  127. {
  128. return false;
  129. }
  130.  
  131. public void addTennant(Tennant tennant)
  132. {
  133. tennants.Add(tennant);
  134. }
  135.  
  136. public void addPhoto(Photo photo)
  137. {
  138. photos.Add(photo);
  139. }
  140.  
  141. public void addIssue(Problem issue)
  142. {
  143. issues.Add(issue);
  144. }
  145.  
  146. public Property(SerializationInfo info, StreamingContext context)
  147. {
  148. // ...
  149. }
  150. public void GetObjectData(SerializationInfo info, StreamingContext context)
  151. {
  152. // ...
  153. }
  154. }
  155.  
  156. // Inside the Constructor
  157. OpenTabs = new ObservableCollection<Object>();
  158. EventManager.RegisterClassHandler(typeof(ListBoxItem),
  159. ListBoxItem.MouseLeftButtonDownEvent,
  160. new RoutedEventHandler(this.OnMouseLeftButtonDown));
  161.  
  162. private void OnMouseLeftButtonDown(object sender, RoutedEventArgs e)
  163. {
  164. ListBoxItem selected = sender as ListBoxItem;
  165. try
  166. {
  167. string t = (selected.Content as Property).title;
  168. Property cur = selected.Content as Property;
  169. OpenProperty(cur);
  170. }
  171. catch (NullReferenceException nre)
  172. {
  173. Tennant cur = selected.Content as Tennant;
  174. OpenTennant(cur);
  175. }
  176. }
  177.  
  178. // This method opens a new tab with a Property's details in it
  179. private void OpenProperty(Property property)
  180. {
  181. this.HomeView.Visibility = System.Windows.Visibility.Hidden;
  182. this.TabbedView.Visibility = System.Windows.Visibility.Visible;
  183. MainWindow.OpenTabs.Add(property);
  184. this.Tabs.SelectedIndex = MainWindow.OpenTabs.IndexOf(property);
  185. }
  186.  
  187. // This method opens a new tab with a Tennant's details in it
  188. private void OpenTennant(Tennant tennant)
  189. {
  190. this.HomeView.Visibility = System.Windows.Visibility.Hidden;
  191. this.TabbedView.Visibility = System.Windows.Visibility.Visible;
  192. MainWindow.OpenTabs.Add(tennant);
  193. this.Tabs.SelectedIndex = MainWindow.OpenTabs.IndexOf(tennant);
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement