2 Replies - 704 Views - Last Post: 17 October 2017 - 03:45 PM

#1 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Understanding how my code steps into another class

Posted 10 October 2017 - 06:59 PM

I am doing currently the Mvvm section on Xamarin University and I debug my code because they already supply code which isn't explained so I try to figure out what is going on. And I realized that when I have my normal class for example

public class MyClass : AnotherClass

the code steps into "AnotherClass".

Here is my code:


this is the app class I make a instance of Page1, and the debugger steps into Page1 object and it goes into the constructor of Page1 then it jumps into the "Class1" class. Which is the code beneath this one:
  public partial class App : Application
    {

        public Page1 Page1 { get; private set; }
        public App()
        {
            InitializeComponent();
            Page1 = new Page1();

            MainPage = new test.MainPage();
        }





code steps into constructor here then into class1
  public class Page1 : Class1
    {
        public Page1()
        {

        }
    }



 public class Class1
    {
        public event PropertyChangedEventHandler PropertyChanged = delegate { };
        public Class1()
        {

        }




Why does it step into class1? I thought it should only if we use the " :base" keyword in the Page1 class, I understand that calls the constructor but doesn't inheritance in this scenario just allow us to derive things from Class1? I don't see why it steps inside it.

Is This A Good Question/Topic? 0
  • +

Replies To: Understanding how my code steps into another class

#2 dckumawat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-October 17

Re: Understanding how my code steps into another class

Posted 17 October 2017 - 04:36 AM

you must declare the List as a property. To access the list from an other class you must give an instance from your List to the other class.

//FilterHistory.xaml.cs
namespace ReportsUIScreens
{
    public partial class FilterHistory : ChildWindow
    {
        private List<filterHistory> histList;
        public FilterHistory(List<filterHistory> histListLink)
        {
            InitializeComponent();  
            histList = histListLink;
            this.HistoryList.ItemsSource=histList;          
        }
 
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            ...
        }
 
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            ...
        }
 
    }
}
 
//SaveFilterHistory.xaml.cs
namespace ReportsUIScreens
{
    public partial class SaveFilterHistory : ChildWindow
    {
        private List<filterHistory> histList;
        public SaveFilterHistory(List<filterHistory> histListLink)
        {
            InitializeComponent();
            histList = histListLink;
        }
 
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            //here's where i wanna add anew filterHistory
            histList.Add(new filterHistory(){FilterName="Filter1", Date=new DateTime(2011, 04, 30)});
            this.DialogResult = true;
        }
 
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}



you must pull out the filterHistory class out of your partial class and paste it simply in the namespace or in a separate .cs file

public class filterHistory
{
   public string FilterName { get; set; }
   public DateTime Date { get; set; }
}




I am working in Mobile App latest version.

Currently making a static mileage tracker for my school district employees.
Was This Post Helpful? 0
  • +
  • -

#3 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Re: Understanding how my code steps into another class

Posted 17 October 2017 - 03:45 PM

I don't think you understand what I am trying to say. I am saying when I am debugging WHY is it going into the other class?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1