views:

479

answers:

2

I can modify/access controls and MessageBox with ease in the MainWindow.xaml.cs file of my WPF application. However, when I create some folders and add classes there, I no longer have access to MessageBox nor do I have see the control names in the Intellisense dropdown.

(This seems quite elementary but I'm new to C# and WPF)

+1  A: 

Does your classes have the right using statement in that would allow you access to the class you are attempting to access within the new classes you've created?

Wil P
A: 

You must be missing a namespace. You could do something like this:


MainWindow.cs:

 using System;
 using System.Text;
 using System.Windows;
 using System.Windows.Controls;

namespace YourNameSpaceHere
{
    public partial class MainWindow : Window
    {
        internal static string message_ = string.Empty;
        MainWindow()
        {
            InitializeComponent();
            SetupMessage();
        }

        private void SetupMessage()
        {
            message_ = "Hello World!";
        }
    }
}


OtherFile.cs :

using System;
using System.Text;
using System.Windows;
using System.Windows.Controls; //are you missing this namespace?
namespace YourNameSpaceHere
{
        public class Messaging
        {
            Messaging()
            {
                MessageBox.Show(MainWindow.message_);
            }
        }
}


Note that I am using the same namespace in each file and by using the internal keyword the message can be accessed by anything as long as it is in the same namespace. I hope this helps!

Partial