Back to Devexpress

Mapping Class

maui-devexpress-dot-maui-dot-scheduler-2ef86204.md

latest7.4 KB
Original Source

Mapping Class

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

Namespace : DevExpress.Maui.Scheduler

Assembly : DevExpress.Maui.Scheduler.dll

NuGet Package : DevExpress.Maui.Scheduler

Declaration

csharp
[TypeConverter(typeof(MappingConverter))]
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 configures 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(recurrence) {
            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 supply data to a scheduler item’s property.

| |

MappingExtension

|

Implements a XAML markup extension that allows you to create a Mapping object.

|

Implements

INotifyPropertyChanged

Inheritance

System.Object DevExpress.Maui.Scheduler.Internal.BindableBase DevExpress.Maui.Scheduler.Internal.FreezableBase Mapping

Extension Methods

Yield<Mapping>()

YieldIfNotNull<Mapping>()

See Also

Mapping Members

DevExpress.Maui.Scheduler Namespace