tags:

views:

32

answers:

1

I have tabcontrol.

At first tabitem I have coordinates in decimal type.

At second tabitem I have coordinates in DMS type.

When user change something one of them I want that this change will affecting second type

Now it only works that when I run application controls for cartesian coordinates are filled. But when I change something after running in decimal coordinates nothing change in controls of cartesian coordinates

class DecimalCoordinatesToCartesianConverter : IValueConverter
    {
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return null;
            }
            else
            {

                DecimalCoordinates decimalCoorinates = (DecimalCoordinates)value;

                CartesianCoorinates cartesianCoorinates = new CartesianCoorinates();

                // Set flag if number is negative
                cartesianCoorinates.LatitudeDirection = (decimalCoorinates.Latitude < (decimal)0d) ? GeoDirectionLatitude.S : GeoDirectionLatitude.N;

                // Work with a positive number
                decimalCoorinates.Latitude = Math.Abs(decimalCoorinates.Latitude);

                // Get d/m/s components
                decimal tempLatitudeDegress = Math.Floor(rdecimalCoorinates.Latitude);
               decimalCoorinates.Latitude -= tempLatitudeDegress;
               decimalCoorinates.Latitude *= 60;
                decimal tempLatitudeMinutes = Math.Floor(decimalCoorinates.Latitude);
                decimalCoorinates.Latitude -= tempLatitudeMinutes;
                decimalCoorinates.Latitude *= 60;
                decimal tempLatitudeSeconds = Math.Round(decimalCoorinates.Latitude);

                // Create padding character
                char padLatitude;
                char.TryParse("0", out padLatitude);


                cartesianCoorinates.LatitudeHours = (int)tempLatitudeDegress;
                cartesianCoorinates.LatitudeMinutes = System.Convert.ToInt32(tempLatitudeMinutes.ToString().PadLeft(2, padLatitude));
                cartesianCoorinates.LatitudeSeconds = System.Convert.ToInt32(tempLatitudeSeconds.ToString().PadLeft(2, padLatitude));


                cartesianCoorinates.LongitudeDirection = (decimalCoorinates.Longitude < (decimal) 0d)
                                                                     ? GeoDirectionLongtitude.W
                                                                     : GeoDirectionLongtitude.E;

                // Work with a positive number
                decimalCoorinates.Longitude = Math.Abs(decimalCoorinates.Longitude);

                // Get d/m/s compon## Heading ##ents
                decimal tempLongitudeDegress = Math.Floor(decimalCoorinates.Longitude);
                decimalCoorinates.Longitude -= tempLongitudeDegress;
                decimalCoorinates.Longitude *= 60;
                decimal tempLongitudeMinutes = Math.Floor(decimalCoorinates.Longitude);
                decimalCoorinates.Longitude -= tempLongitudeMinutes;
                decimalCoorinates.Longitude *= 60;
                decimal tempLongitudeSeconds = Math.Round(decimalCoorinates.Longitude);

                // Create padding character
                char padLongitude;
                char.TryParse("0", out padLongitude);


                cartesianCoorinates.LongitudeHours = (int)tempLongitudeDegress;
               cartesianCoorinates.LongitudeMinutes = System.Convert.ToInt32(tempLongitudeMinutes.ToString().PadLeft(2, padLongitude));
                cartesianCoorinates.LongitudeSeconds = System.Convert.ToInt32(tempLongitudeSeconds.ToString().PadLeft(2, padLongitude));



                return cartesianCoorinates;



            }
        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return parameter;
        }
}


public class HotelDescriptionModelView
    {
        HotelDescription hotelDescription { get; set; }

        public HotelDescriptionModelView()
        {
            hotelDescription = new HotelDescription();

            hotelDescription.DecimalCoordinates = new DecimalCoordinates() { Latitude = (decimal)-89.67, Longitude = (decimal)-89.67 };
        }
        public DecimalCoordinates DecimalCoordinates
        {
            get
            {
                return this.hotelDescription.DecimalCoordinates;
            }
            set
            {
                this.hotelDescription.DecimalCoordinates = value;
            }
        }

        public CartesianCoordinates CartesianCoordinates
        {
            get
            {
                return this._hotelDescription.CartesianCoordinates;
            }
            set
            {
                this._hotelDescription.CartesianCoordinates = value;
            }
        }

    }


  public class CartesianCoordinates
    {
        public int LatitudeHours { get; set;}
        public int LatitudeMinutes { get; set; }
        public int LatitudeSeconds { get; set; }
        public GeoDirectionLongtitude LongitudeDirection { get; set; }

        public int LongitudeHours { get; set; }
        public int LongitudeMinutes { get; set; }
        public int LongitudeSeconds { get; set; }
        public GeoDirectionLatitude LatitudeDirection { get; set; }
    }

public class DecimalCoordinates
    {
        public decimal Latitude { get; set; }
        public decimal Longitude { get; set; }
    }

public enum GeoDirectionLongtitude
    {
        W=0,
        E=1
    }

public enum GeoDirectionLatitude
    {
        N=0,
        S=1
    }
+1  A: 

You need to implement INotifyPropertyChanged in your classes and fire events when your properties change. Otherwise WPF doesn't know the value is different.

Steve Mitcham