Можно использовать только один столбец в вашей DataGrid с помощью преобразователя значений
// If you don't specify a property path, Silverlight uses the entire object
// For two way binding make sure you bind it to an IList<LocationWrapper>
var theOneColumn = new DataGridTextColumn (
Header = "Long + Lat",
Binding = new Binding(){
Mode = BindingMode.TwoWay,
Converter = new LongLatConverter()
}
);
//Converter
public class LongLatConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var loc = value as LocationWrapper;
return String.Format("Long: {0}, Lat: {0}", loc.Longitude, loc.Latitude);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
//...
}
}
//Wrapper class for Location so two way binding works
public class LocationWrapper
{
//The actual location object
public String Location( get; set;}
public LocationWrapper(Location loc)
{
this.Location = loc;
}
}
Для преобразования, основанного на части флага, вы можете передать параметр Converter, чтобы изменить поведение преобразователя.
var theOneColumn = new DataGridTextColumn (
Header = "Long + Lat",
Binding = new Binding(){
Mode = BindingMode.TwoWay,
Converter = new LongLatConverter(),
ConverterParameter = "UTM" // This is what you want to set
}
);
// ....
// In the Value Converter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var loc = value as Location;
if( (parameter as string).equals("UTM"))
{
//return UTM formated long/lat coordinates
}
else
{
return String.Format("Long: {0}, Lat: {0}", loc.Longitude, loc.Latitude);
}
}