2010-07-07 44 views
0

我有tabcontrol。Wpf中的動態轉換器

首先tabitem我有十進制類型的座標。

在第二個tabitem我有DMS類型的座標。

當用戶改變他們的東西之一,我想,這種變化將影響第二類

現在它只能當我運行笛卡爾座標應用控制被填充。但是,當我改變的東西在小數點後運行座標笛卡爾的控制沒有變化的座標

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

您需要執行INotifyPropertyChanged在你的類和火災事件,當你的屬性發生改變。否則WPF不知道這個值是不同的。