Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# updating controls using events from another class

Posted on 2010-11-10
6
Medium Priority
?
778 Views
Last Modified: 2013-12-27
Hey guys,

i'm basically trying to use an event defined in another class to update a control in a separate class, no errors, but the event doesn't seem to be firing, I'm obviously doing something wrong but just don't know what.
public class GPSCommand
{
    public GeoCoordinateWatcher GeoWatcher;

    public event EventHandler<GeoPositionStatusChangedEventArgs>
    GeoWatcher_Status;

    public void StartGeoWatcher()
    {
            
        if (GeoWatcher == null)
        {
            GeoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
 
            GeoWatcher.MovementThreshold = 20;

            GeoWatcher.Start();

        }

    }

}

// And then the class with the event handler function...

public partial class MainPage : PhoneApplicationPage
{
    private GPSCommand GPS = new GPSCommand();

    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        // Get current position..
        GPS.StartGeoWatcher();
        GPS.GeoWatcher_Status += new EventHandler<System.Device.Location.GeoPositionStatusChangedEventArgs>(GPS_GeoWatcher_StatusChanged);
        }

        // Event handler for the GeoCoordinateWatcher.StatusChanged event.
        private void GPS_GeoWatcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
        {
            switch (e.Status)
            {
                case GeoPositionStatus.Disabled:
                    // The Location Service is disabled or unsupported.
                    // Check to see if the user has disabled the Location Service.
                    if (GPS.GeoWatcher.Permission == GeoPositionPermission.Denied)
                    {
                        
                        // The user has disabled the Location Service on their device.

                        tbStatus.Text = "you have this application access to location.";
                    }
                    else
                    {
                        tbStatus.Text = "location is not functioning on this device";
                    }
                    break;

                case GeoPositionStatus.Initializing:
                    tbStatus.Text = "Initializind data location service...";
                    //startLocationButton.IsEnabled = false;
                    break;

                case GeoPositionStatus.NoData:
                    tbStatus.Text = "location data is not available.";
                    //stopLocationButton.IsEnabled = true;
                    break;

                case GeoPositionStatus.Ready:
                    tbStatus.Text = "location data is available.";
                    //stopLocationButton.IsEnabled = true;
                    break;
            }
        }
    }

Open in new window

0
Comment
Question by:aarmstr2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 24

Accepted Solution

by:
alexey_gusev earned 2000 total points
ID: 34100983
sorry for being dumb :) , but where's the code where you actually fire the event in your 1st class code? something like

...
if (GeoWatcher_Status != null)
     GeoWatcher_Status();
...
0
 
LVL 1

Author Comment

by:aarmstr2
ID: 34101154
Doh, i can such a restard sometimes! Changed this line as follows;-

GPS.GeoWatcher_Status += new EventHandler<System.Device.Location.GeoPositionStatusChangedEventArgs>(GPS_GeoWatcher_StatusChanged);

to....

GPS.GeoWatcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(GPS_GeoWatcher_StatusChanged);

Works now... :S
0
 
LVL 1

Author Closing Comment

by:aarmstr2
ID: 34101157
For making me think!
0
Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

 
LVL 1

Author Comment

by:aarmstr2
ID: 34101171
btw, do u really think my code was 1st class or were u being sarcastic?
0
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 34101222
ah, all I meant is to save on typing the class name, sorry :) , so it was as in "your first class" :)
0
 
LVL 1

Author Comment

by:aarmstr2
ID: 34101230
lol
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question