private void gcw_PositionChanged(object sender, GeoPositionChangedEventArgs e)
 {
     // Stop the GeoCoordinateWatcher now that we have the device location.
     this.gcw.Stop();
     bannerAd.LocationLatitude = e.Position.Location.Latitude;
     bannerAd.LocationLongitude = e.Position.Location.Longitude;
     AdGameComponent.Current.Enabled = true;
 }


知道是什么原因导致此错误吗?

 public void CreateAd()
        {
            int width = 480;
            int height = 80;
            int x = (GraphicsDevice.Viewport.Bounds.Width - width) / 2;
            int y = 720;
            bannerAd = adGameComponent.CreateAd(AdUnitId, new Rectangle(x, y, width, height),
              true);
            // Set some visual properties (optional).
            //bannerAd.BorderEnabled = true; // default is true
            //bannerAd.BorderColor = Color.White; // default is White
            //bannerAd.DropShadowEnabled = true; // default is true
            // Provide the location to the ad for better targeting (optional).
            // This is done by starting a GeoCoordinateWatcher and waiting for the location to
            // available.
            // The callback will set the location into the ad.
            // Note: The location may not be available in time for the first ad request.
            adGameComponent.Enabled = false;
            this.gcw = new GeoCoordinateWatcher();
            this.gcw.PositionChanged += new
              EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>
              (gcw_PositionChanged);
            this.gcw.Start();
        }

Error   1   Using the generic type 'System.Device.Location.GeoPositionChangedEventArgs<T>' requires 1 type arguments


&&

错误2使用通用类型'System.Device.Location.GeoPositionChangedEventArgs'需要1个类型参数

最佳答案

这就是我一直这样做的方式。

声明委托的格式,所有处理程序都将使用此格式

public delegate void gcw_PosChangedEventHandler(GeoPositionChangedEventArgs args);


声明一个其他人可以注册的活动

public event gcw_PosChangedEventHandler gcw_PosChanged;


注册活动

someOtherClass.gcw_PosChanged += this.gcw_PositionChanged;


通过直接触发事件来使事件发生。

// Inside of 'someOtherClass'
gcw_PosChanged(args);


处理我们之前注册的事件。

private void gcw_PositionChanged(GeoPositionChangedEventArgs args)
{
    // Stop the GeoCoordinateWatcher now that we have the device location.
    this.gcw.Stop();
    bannerAd.LocationLatitude = e.Position.Location.Latitude;
    bannerAd.LocationLongitude = e.Position.Location.Longitude;
    AdGameComponent.Current.Enabled = true;
}

关于c# - XNA WP7上的广告,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9065084/

10-10 07:38