You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Syncfusion SfScheduler .NET MAUI:多属性创建约会受限的解决方案咨询

解决方案:突破SchedulerAppointment类属性限制实现多属性约会模板
  • 包装类扩展法
    创建一个AppointmentTemplate包装类,内部持有SchedulerAppointment实例,同时维护多个Background、Notes的集合。使用时可根据场景切换或组合这些属性值,赋值给内部的SchedulerAppointment后再执行后续操作:
public class AppointmentTemplate
{
    private SchedulerAppointment _baseAppointment;
    public List<string> Backgrounds { get; set; } = new List<string>();
    public List<string> NotesCollection { get; set; } = new List<string>();

    public AppointmentTemplate(SchedulerAppointment baseAppt)
    {
        _baseAppointment = baseAppt;
    }

    // 根据索引切换当前使用的Background
    public void SetBackground(int index)
    {
        if (index >= 0 && index < Backgrounds.Count)
        {
            _baseAppointment.Background = Backgrounds[index];
        }
    }

    // 获取所有Notes的组合文本
    public string GetCombinedNotes()
    {
        return string.Join(Environment.NewLine, NotesCollection);
    }
}
  • 附加属性存储法
    用字典存储额外的属性集合,通过扩展方法关联到SchedulerAppointment实例,既不修改原类,又能保存多组属性数据:
public static class AppointmentExtensions
{
    private static readonly Dictionary<SchedulerAppointment, Dictionary<string, List<object>>> _extraProperties = new Dictionary<SchedulerAppointment, Dictionary<string, List<object>>>();

    public static void AddExtraProperty(this SchedulerAppointment appt, string propName, object value)
    {
        if (!_extraProperties.ContainsKey(appt))
        {
            _extraProperties[appt] = new Dictionary<string, List<object>>();
        }
        if (!_extraProperties[appt].ContainsKey(propName))
        {
            _extraProperties[appt][propName] = new List<object>();
        }
        _extraProperties[appt][propName].Add(value);
    }

    public static List<object> GetExtraProperties(this SchedulerAppointment appt, string propName)
    {
        return _extraProperties.TryGetValue(appt, out var props) && props.TryGetValue(propName, out var values) 
            ? values 
            : new List<object>();
    }
}

使用示例:

var appt = new SchedulerAppointment();
appt.AddExtraProperty("Background", "#FF0000");
appt.AddExtraProperty("Background", "#00FF00");
var backgrounds = appt.GetExtraProperties("Background");
  • 模板实例映射法
    若需要基于多组属性生成不同约会实例,可创建模板配置类存储多组属性值,再批量生成SchedulerAppointment实例:
public class AppointmentTemplateConfig
{
    public List<Dictionary<string, object>> PropertySets { get; set; } = new List<Dictionary<string, object>>();
}

// 生成约会实例
public List<SchedulerAppointment> GenerateAppointments(AppointmentTemplateConfig config)
{
    var appointments = new List<SchedulerAppointment>();
    foreach (var props in config.PropertySets)
    {
        var appt = new SchedulerAppointment();
        if (props.ContainsKey("Background"))
            appt.Background = props["Background"].ToString();
        if (props.ContainsKey("Notes"))
            appt.Notes = props["Notes"].ToString();
        appointments.Add(appt);
    }
    return appointments;
}

内容的提问来源于stack exchange,提问作者Vladyslav Malin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 18:43:16