Back to Devexpress

MappingExtension Class

maui-devexpress-dot-maui-dot-scheduler-0cc86bb3.md

latest5.1 KB
Original Source

MappingExtension Class

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

Namespace : DevExpress.Maui.Scheduler

Assembly : DevExpress.Maui.Scheduler.dll

NuGet Package : DevExpress.Maui.Scheduler

Declaration

csharp
[AcceptEmptyServiceProvider]
public class MappingExtension :
    IMarkupExtension

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

IMarkupExtension

Inheritance

System.Object MappingExtension

Extension Methods

Yield<MappingExtension>()

YieldIfNotNull<MappingExtension>()

See Also

MappingExtension Members

DevExpress.Maui.Scheduler Namespace