Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <view:CustomTabControl ItemsSource="{Binding OpenTabs}" Grid.Column="1" x:Name="Tabs">
- <view:CustomTabControl.Resources>
- <DataTemplate DataType="{x:Type model:Tennant}">
- <ScrollViewer>
- <Grid>
- <TextBlock Text="{Binding name}"/>
- </Grid>
- </ScrollViewer>
- </DataTemplate>
- <DataTemplate DataType="{x:Type model:Property}">
- <ScrollViewer>
- <Grid MinWidth="350">
- <!-- All of the stuff that works for the Property layout in here -->
- </Grid>
- </ScrollViewer>
- </DataTemplate>
- </view:CustomTabControl.Resources>
- </view:CustomTabControl>
- <ScrollViewer VerticalScrollBarVisibility="Auto">
- <StackPanel>
- <TextBlock Margin="10,5" Text="Properties" FontSize="16"/>
- <ListBox x:Name="propertiesList" ItemsSource="{Binding Properties, Mode=TwoWay}">
- <ListBox.ItemTemplate>
- <DataTemplate DataType="{x:Type model:Property}">
- <TextBlock Text="{Binding title}"/>
- </DataTemplate>
- </ListBox.ItemTemplate>
- </ListBox>
- <TextBlock Margin="10,5" Text="Tennants" FontSize="16"/>
- <ListBox x:Name="tennantsList" ItemsSource="{Binding Tennants, Mode=TwoWay}">
- <ListBox.ItemTemplate>
- <DataTemplate DataType="{x:Type model:Tennant}">
- <TextBlock Text="{Binding name}"/>
- </DataTemplate>
- </ListBox.ItemTemplate>
- </ListBox>
- </StackPanel>
- </ScrollViewer>
- [Serializable]
- public class Tennant : ISerializable, INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- private bool current;
- private string name;
- private string phone;
- private string email;
- private string occupation;
- public bool Current { get { return current; } set { current = value; OnPropertyChanged("Current"); } }
- public string Name { get { return name; } set { name = value; OnPropertyChanged("Name"); } }
- public string Phone { get { return phone; } set { phone = value; OnPropertyChanged("Phone"); } }
- public string Email { get { return email; } set { email = value; OnPropertyChanged("Email"); } }
- public string Occupation { get { return occupation; } set { occupation = value; OnPropertyChanged("Occupation"); } }
- public Tennant()
- {
- }
- public Tennant(bool current, string name, string phone, string email, string occupation)
- {
- this.Current = current;
- this.Name = name;
- this.Phone = phone;
- this.Email = email;
- this.Occupation = occupation;
- }
- private void OnPropertyChanged(string p)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(p));
- }
- }
- public override string ToString()
- {
- return "" + Current + " " + Name + " " + Phone + " " + Email + " " + Occupation;
- }
- public Tennant(SerializationInfo info, StreamingContext context)
- {
- this.Current = (bool)info.GetValue("Current", typeof(bool));
- this.Name = (string)info.GetValue("Name", typeof(string));
- this.Phone = (string)info.GetValue("Phone", typeof(string));
- this.Email = (string)info.GetValue("Email", typeof(string));
- this.Occupation = (string)info.GetValue("Occupation", typeof(string));
- }
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- info.AddValue("Current", this.Current);
- info.AddValue("Name", this.Name);
- info.AddValue("Phone", this.Phone);
- info.AddValue("Email", this.Email);
- info.AddValue("Occupation", this.Occupation);
- }
- }
- public class Property : ISerializable
- {
- public string address { get; set; }
- public string city { get; set; }
- public string postcode { get; set; }
- // ...
- public Property()
- {
- // ...
- }
- public string toString()
- {
- return title;
- }
- public bool hasPhotos()
- {
- return false;
- }
- public bool hasTennant()
- {
- return false;
- }
- public void addTennant(Tennant tennant)
- {
- tennants.Add(tennant);
- }
- public void addPhoto(Photo photo)
- {
- photos.Add(photo);
- }
- public void addIssue(Problem issue)
- {
- issues.Add(issue);
- }
- public Property(SerializationInfo info, StreamingContext context)
- {
- // ...
- }
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- // ...
- }
- }
- // Inside the Constructor
- OpenTabs = new ObservableCollection<Object>();
- EventManager.RegisterClassHandler(typeof(ListBoxItem),
- ListBoxItem.MouseLeftButtonDownEvent,
- new RoutedEventHandler(this.OnMouseLeftButtonDown));
- private void OnMouseLeftButtonDown(object sender, RoutedEventArgs e)
- {
- ListBoxItem selected = sender as ListBoxItem;
- try
- {
- string t = (selected.Content as Property).title;
- Property cur = selected.Content as Property;
- OpenProperty(cur);
- }
- catch (NullReferenceException nre)
- {
- Tennant cur = selected.Content as Tennant;
- OpenTennant(cur);
- }
- }
- // This method opens a new tab with a Property's details in it
- private void OpenProperty(Property property)
- {
- this.HomeView.Visibility = System.Windows.Visibility.Hidden;
- this.TabbedView.Visibility = System.Windows.Visibility.Visible;
- MainWindow.OpenTabs.Add(property);
- this.Tabs.SelectedIndex = MainWindow.OpenTabs.IndexOf(property);
- }
- // This method opens a new tab with a Tennant's details in it
- private void OpenTennant(Tennant tennant)
- {
- this.HomeView.Visibility = System.Windows.Visibility.Hidden;
- this.TabbedView.Visibility = System.Windows.Visibility.Visible;
- MainWindow.OpenTabs.Add(tennant);
- this.Tabs.SelectedIndex = MainWindow.OpenTabs.IndexOf(tennant);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement