Back to Devexpress

Mapping Class

mobilecontrols-devexpress-dot-xamarinforms-dot-scheduler-a20a7123.md

latest7.7 KB
Original Source

Mapping Class

The property mapping that specifies source object’s property that provides data to a scheduler item’s property.

Namespace : DevExpress.XamarinForms.Scheduler

Assembly : DevExpress.XamarinForms.Scheduler.dll

NuGet Package : DevExpress.XamarinForms.Scheduler

Declaration

csharp
public class Mapping :
    FreezableBase

The following members return Mapping objects:

Show 20 links

Remarks

Note that you can specify this property’s value using one of the following approaches:

  • By a source object’s property name. The label mapping creates the property mapping without converters:

  • Via the markup extension. You can specify all mapping settings in this case:

  • Assigning a new Mapping object to the property.

Example

This example demonstrates how to configure mappings that specify the properties of source objects and how they provide values for scheduler items’ properties.

xml
<ContentPage.Resources>
    <views:ModelRecurrenceToRecurrenceInfoConverter x:Key="recurrenceConverter"/>
    <views:MedicalAppointmentTypeToAppointmentTypeConverter x:Key="appointmentTypeConverter"/>
</ContentPage.Resources>
<!-- Some markup is skipped. -->
<dxs:DataSource AppointmentsSource="{Binding MedicalAppointments}">
    <dxs:DataSource.AppointmentMappings>
        <dxs:AppointmentMappings 
            Id="Id" 
            Subject="Subject"
            End="EndTime" 
            Start="StartTime" 
            LabelId="LabelId"
            Type="{dxs:Mapping FieldName=Type, Converter={StaticResource appointmentTypeConverter}, ConversionBehavior=InPlaceOfMapping}">
            <!-- The extension above configures the mapping like the following. -->
            <dxs:AppointmentMappings.RecurrenceInfo>
                <dxs:Mapping 
                    FieldName="Recurrence" 
                    Converter="{StaticResource recurrenceConverter}"
                    ConversionBehavior="InPlaceOfMapping"/>
            <dxs:AppointmentMappings.RecurrenceInfo>
    </dxs:DataSource.AppointmentMappings>
<dxs:DataSource
csharp
class ModelRecurrenceToRecurrenceInfoConverter : IValueConverter {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
        if (!(value is MedicalAppointmentRecurrence recurrence)) return null;

        IRecurrenceInfo info = new RecurrenceInfo();
        info.Start = DateTime.Now;
        info.End = DateTime.Now.AddYears(10);
        info.Periodicity = 1;
        switch(info) {
            case MedicalAppointmentRecurrence.Weekly: info.Type = RecurrenceType.Weekly; break;
            case MedicalAppointmentRecurrence.Monthly: info.Type = RecurrenceType.Monthly; break;
            case MedicalAppointmentRecurrence.Yearly: info.Type = RecurrenceType.Yearly; break;
            default: throw new Exception("The specified MedicalAppointmentRecurrence value does not supported.")
        }

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

class MedicalAppointmentTypeToAppointmentTypeConverter : IValueConverter {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
        if (!(value is MedicalAppointmentType type)) return AppointmentType.Normal;
        switch(type) {
            case MedicalAppointmentType.Regular: return AppointmentType.Normal;
            case MedicalAppointmentType.Recurrent: return AppointmentType.Pattern;
            default: throw new Exception("The specified MedicalAppointmentType value does not supported.")
        }
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
        return null;
    }
}
csharp
public class MedicalAppointment {
    public int Id { get; set; }
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
    public string Subject { get; set; }
    public int LabelId { get; set; }
    public MedicalAppointmentRecurrence Recurrence { get; set; }
    public MedicalAppointmentType Type { get; set; }
}

public enum MedicalAppointmentRecurrence {
    None,
    Weekly,
    Monthly, 
    Yearly
}

public enum MedicalAppointmentType {
    Regular,
    Recurrent
}

The code above uses the classes and members below:

|

Symbol

|

Description

| | --- | --- | |

Mapping

|

The property mapping that specifies source object’s property that provides data to a scheduler item’s property.

| |

MappingExtension

|

Implements a XAML markup extension in order to create a Mapping object.

|

Implements

INotifyPropertyChanged

Inheritance

Object DevExpress.XamarinForms.Scheduler.Internal.BindableBase DevExpress.XamarinForms.Scheduler.Internal.FreezableBase Mapping

See Also

Mapping Members

DevExpress.XamarinForms.Scheduler Namespace