如何在一次约会 Syncfusion SfScheduler .NET MAUI(或 DevExpress Scheduler)中将一个属性用于两个不同的目的?

问题描述 投票:0回答:1

问题:我在 .NET MAUI 应用程序中使用 SfScheduler 来显示时间表。我有一个约会模板,我想为约会的不同部分设置不同的背景。例如,我想对一个部分使用从Background 属性获取的背景颜色,对另一部分使用通过AppointmentStatusColor 属性定义的状态颜色。但是,我遇到了一个问题,因为我无法在模板中两次使用“背景”属性。如何解决这个问题并为约会的不同部分设置不同的背景?其他 Notes 属性等也存在类似问题......

我创建了一个目标模板,其中使用 Background="{Binding Background}" 作为约会的整体背景。 我还有 BoxView Background="#8239BC",我必须使用接收到的数据中的背景颜色,而不是硬编码颜色:

<ContentPage.Resources>
    <DataTemplate x:Key="dayAppointmentTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <BoxView Background="#8239BC" WidthRequest="4" VerticalOptions="FillAndExpand" Grid.Column="0"/>
            <StackLayout Background="{Binding Background}" Grid.Column="1">
                <Label Text="{Binding Subject}" TextColor="#3B3E45" LineBreakMode="TailTruncation" FontSize="14" FontFamily="Noto Sans" Margin="8,2,0,0" HorizontalOptions="Start" VerticalOptions="Start"/>
                <Label Text="{Binding Notes}" TextColor="#666E7D" LineBreakMode="TailTruncation" FontSize="10" FontFamily="Noto Sans" Margin="8,0,5,5" HorizontalOptions="Start" VerticalOptions="Start"/>
            </StackLayout>
        </Grid>
    </DataTemplate>
</ContentPage.Resources>

Background="UserColor" 这里我们已经使用了Background来显示背景UserColor,但是我们需要获取另一个颜色StatusColor,但是我们不能第二次使用Background。

<scheduler:SfScheduler.AppointmentMapping>
    <scheduler:SchedulerAppointmentMapping StartTime="EventStartDateTime"
                       EndTime="EventEndDateTime"
                       Subject="PatientName"
                       Background="UserColor"
                       Notes="AppointmentStatus"
                       />
</scheduler:SfScheduler.AppointmentMapping>

其他属性也有类似的问题,因为我的约会设计使用两种不同的背景颜色,添加了两个以上的图标和描述。

这个问题有什么解决办法吗?还是仍然无法绕过预约的财产限制?

我也可能会考虑 DevExpress 调度程序

devexpress maui scheduler syncfusion syncfusion-calendar
1个回答
0
投票

如果您使用调度程序预约源映射,您可能会发现只有有限的属性。因此,您不能定义其他属性,例如 StatusColor 等。

作为解决方法,您可以自定义自己的

SchedulerAppointment
并且不使用源映射。

这里我定义了一个

CustomAppointment
类,它是
SchedulerAppointment
的子类,并且有一个名为 AnotherColor 的新属性。

public class CustomAppointment : SchedulerAppointment
{
    public SolidColorBrush AnotherColor { get; set; } = new SolidColorBrush(Color.FromArgb("#FFFF0000"));

}

ViewModel中,生成约会,

public class SchedulerViewModel
{
  
    ...
    public ObservableCollection<CustomAppointment> Events { get; set; }
    private void GenerateAppointments()
    {
        this.Events = new ObservableCollection<CustomAppointment>();
        //Adding the schedule appointments in the schedule appointment collection.
        this.Events.Add(new CustomAppointment
        {
            StartTime = DateTime.Now.Date.AddHours(10),
            EndTime = DateTime.Now.Date.AddHours(11),
            Subject = "Client Meeting",
            Background = new SolidColorBrush(Color.FromArgb("#FF8B1FA9")),
            AnotherColor = new SolidColorBrush(Color.FromArgb("#FFFF0000")),
        });
        this.Events.Add(new CustomAppointment
        {
            StartTime = DateTime.Now.Date.AddDays(1).AddHours(13),
            EndTime = DateTime.Now.Date.AddDays(1).AddHours(14),
            Subject = "GoToMeeting",
            Background = new SolidColorBrush(Color.FromArgb("#FFD20100")),
            AnotherColor = new SolidColorBrush(Color.FromArgb("#FFFF0000")),
        });
    }
}

XAML中使用它,无需使用源映射,

<scheduler:SfScheduler x:Name="Scheduler" 
                       ...                     
                       AppointmentsSource="{Binding Events}"
                       >
    <scheduler:SfScheduler.DaysView>
        <scheduler:SchedulerDaysView AppointmentTemplate="{StaticResource dayAppointmentTemplate}"/>
    </scheduler:SfScheduler.DaysView>
</scheduler:SfScheduler>

在DataTemplate中,只需简单地使用不同颜色的绑定,例如,

<BoxView Background="{Binding AnotherColor}"
<StackLayout Background="{Binding Background}"

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.