'System.InvalidCastException in foreach

im making an app in Visual Studio uwp and have a stack panel to store usercontrol objects. I want to access the array of the usercontrols within the stackpanel with a foreach loop. There is an error that says that it could not convert a button to: "Unable to cast object of type 'Windows.UI.Xaml.Controls.Button' to type 'PopNotes.NotiObject'.'" Does anyone know what the problem is?

code:

ArrayList notiList = new ArrayList();
    
        DispatcherTimer timer = new DispatcherTimer();
        int count = 0;
    
        public MainPage()
        {
            this.InitializeComponent();
            notificationController();
    
            foreach (NotiObject noti in itemsPanel.Children)
            {
                notiList.Add(noti);
                System.Diagnostics.Debug.WriteLine(noti);
            }
    
    
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source