程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了基于账单类型的项目集合视图背景颜色的风格化 转换器XML大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决基于账单类型的项目集合视图背景颜色的风格化 转换器XML?

开发过程中遇到基于账单类型的项目集合视图背景颜色的风格化 转换器XML的问题如何解决?下面主要结合日常开发的经验,给出你关于基于账单类型的项目集合视图背景颜色的风格化 转换器XML的解决方法建议,希望对你解决基于账单类型的项目集合视图背景颜色的风格化 转换器XML有所启发或帮助;

我想为我的集合视图提供与同步融合日历组件中相同样式的集合视图项的颜色样式,我将如何使用集合视图执行此操作。我有一个名为 BillType 的项目,它会突出显示不同颜色的红色用于健康保险蓝色用于汽车保险等。

我希望能够像圆角一样设计它

为了清除它的集合视图的行,我想根据类型改变颜色

<CollectionVIEw x:name="ItemsListVIEw"
            Itemssource="{Binding Bills}"
            SELEctionMode="None">
        <CollectionVIEw.ItemTemplate>
            <DataTemplate>
                <StackLayout padding="10"  x:DataType="model:Bills"> 
                    <Label Text="{Binding  PricE}" 
                        lineBreakmode="nowrap" 
                        Style="{Dynamicresource ListItemTextStylE}" 
                        FontSize="16" />
                    <Label Text="{Binding Description}" 
                        lineBreakmode="nowrap"
                        Style="{Dynamicresource ListItemDetailTextStylE}"
                        FontSize="13" />
                    <StackLayout.GestureRecognizers>
                        <TapGestureRecognizer 
                            numberOfTapsrequired="1"
                            Command="{Binding source={relativesource AncestorType={x:Type local:Billsviewmodel}},Path=ItemTappeD}"     
                            CommandParameter="{Binding .}">
                        </TapGestureRecognizer>
                    </StackLayout.GestureRecognizers>
                </StackLayout>
            </DataTemplate>
        </CollectionVIEw.ItemTemplate>
    </CollectionVIEw>
    </refreshVIEw>
</StackLayout>

https://Help.syncfusion.com/xamarin/calendar/calendar-events

基于账单类型的项目集合视图背景颜色的风格化
      
    转换器XML

我想从日历中复制紫色和绿色,以便样式匹配

基于账单类型的项目集合视图背景颜色的风格化
      
    转换器XML

解决方法

您可以使用 Converter 将类型转换为颜色。

转换器

 public class TypeToColorConverter : IValueConverter
    {
        public object Convert(object value,Type targetType,object parameter,CultureInfo culturE)
        {
            var type = value as String;
            if (type == "xxx")
            {
                return Color.Green;
            }                
            else if(type == "aaa")
            {
                return Color.Purple;
            }

            return Color.White;
        }


        public object ConvertBACk(object value,CultureInfo culturE)
        {
            return "";
        }

    }

XML

  <ContentPage.resources>
        <resourceDictionary>
            <local:TypeToColorConverter  x:Key="c" />
        </resourceDictionary>
    </ContentPage.resources>


 
 <DataTemplate>
       <StackLayout Padding="10" BACkgroundColor="{Binding type,Converter={Staticresource c}}">

,
#Regarding Syling of the collection view BACkground colour of items based on Bill type
We have checked the reported query from our end. we would like to inform you that you can achieve your requirements of custom agenda view with collectionview. Please refer to the following code snippet for your reference.

Code snippet
<ContentPage.resources>
        <resourceDictionary>
            <local:datetiR_32_11845@eToStringConverter x:Key="StringConverter"/>
        </resourceDictionary>
    </ContentPage.resources>
    <ContentPage.behaviors>
        <local:CalendarBehavior/>
    </ContentPage.behaviors>
  <StackLayout Padding="0,30,0">
   <syncfusion:SfCalendar x:Name="Calendar" ShowInlineEvents="false" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
        <CollectionView x:Name="ListView">
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Grid BACkgroundColor="{Binding Color}">
                            <Grid.columnDefinitions>
                                <columnDefinition Width="Auto"/>
                                <columnDefinition Width="*"/>
                            </Grid.columnDefinitions>
                            <StackLayout Orientation="Vertical" Grid.column="0">
                                <Label Text = "{Binding StartTime,Converter={Staticresource StringConverter}}" FontSize="14" />
                                <Label Text="{Binding EndTime,Converter={Staticresource StringConverter}}" FontSize="14"/>
                            </StackLayout>
                            <StackLayout Orientation="Vertical" Padding="40,0" Grid.column="1">
                                <Label Text = "{Binding Subject}" FontSize="20" FontAttributes="Bold" />
                            </StackLayout>
                        </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </StackLayout>
</ContentPage>

Behavior Class
public class CalendarBehavior : Behavior<ContentPage>
    {
        private SfCalendar calendar;
        CollectionView listView;
        private CalendarEventCollection calendarInlineEvents;
        private ObservableCollection<String> meeTingSubjectCollection;
        private ObservableCollection<Color> colorCollection;
        public CalendarBehavior()
        {
            calendarInlineEvents = new CalendarEventCollection();
            this.AddAppointmentDetails();
            this.AddAppointments();
        }

        protected override void OnAttachedTo(ContentPage bindablE)
        {
            var page = bindable as Page;
            calendar = page.FindByName<SfCalendar>("Calendar");
            listView = page.FindByName<CollectionView>("ListView");
            calendar.SELEctionChanged += Calendar_SELEctionChanged;
            listView.Itemssource = GetSELEctedDateAppointments(datetiR_32_11845@e.Now.DatE);
            // SetTing Datasource for 3 Months.
            calendar.Datasource = calendarInlineEvents;
            base.onAttachedTo(bindablE);
        }

        protected override void OnDetachingFrom(ContentPage bindablE)
        {
            calendar.SELEctionChanged -= Calendar_SELEctionChanged;
            base.onDetachingFrom(bindablE);
        }

        /// <sumMary>
        /// Calendars the SELEction changed.
        /// </sumMary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        void Calendar_SELEctionChanged(object sender,Syncfusion.SfCalendar.XForms.SELEctionChangedEventArgs E)
        {
            // SetTing Itemsource for ListView based on appointment SELEction
            listView.Itemssource = GetSELEctedDateAppointments(calendar.SELEctedDatE);
        }

        /// <sumMary>
        /// Gets the SELEcted date appointments.
        /// </sumMary>
        /// <returns>The SELEcted date appointments.</returns>
        /// <param name="date">Date.</param>
        public CalendarEventCollection GetSELEctedDateAppointments(datetiR_32_11845@e? datE)
        {
            CalendarEventCollection SELEctedDateAppointments = new CalendarEventCollection();
            for (int i = 0; i < calendarInlineEvents.Count; i++)
            {
                datetiR_32_11845@e startDate = calendarInlineEvents[i].StartTime;

                if (date.Value.Day == startDate.Day && date.Value.Month == startDate.Month && date.Value.Year == startDate.Year)
                {
                    SELEctedDateAppointments.Add(calendarInlineEvents[i]);
                }
            }
            return SELEctedDateAppointments;
        }

        /// <sumMary>
        /// Adds the appointment details.
        /// </sumMary>
        private void AddAppointmentDetails()
        {
            meeTingSubjectCollection = new ObservableCollection<String>();
            meeTingSubjectCollection.Add("General MeeTing");
            meeTingSubjectCollection.Add("Plan Execution");
            meeTingSubjectCollection.Add("Project Plan");
            meeTingSubjectCollection.Add("ConsulTing");
            meeTingSubjectCollection.Add("Support");
            meeTingSubjectCollection.Add("Development MeeTing");
            meeTingSubjectCollection.Add("Scrum");
            meeTingSubjectCollection.Add("Project Completion");
            meeTingSubjectCollection.Add("Release updates");
            meeTingSubjectCollection.Add("PerfoRMANce check");

            colorCollection = new ObservableCollection<Color>();
            colorCollection.Add(Color.FromHex("#FFA2C139"));
            colorCollection.Add(Color.FromHex("#FFD80073"));
            colorCollection.Add(Color.FromHex("#FF1BA1E2"));
            colorCollection.Add(Color.FromHex("#FFE671B8"));
            colorCollection.Add(Color.FromHex("#FFF09609"));
            colorCollection.Add(Color.FromHex("#FF339933"));
            colorCollection.Add(Color.FromHex("#FF00ABA9"));
            colorCollection.Add(Color.FromHex("#FFE671B8"));
            colorCollection.Add(Color.FromHex("#FF1BA1E2"));
            colorCollection.Add(Color.FromHex("#FFD80073"));
            colorCollection.Add(Color.FromHex("#FFA2C139"));
            colorCollection.Add(Color.FromHex("#FFA2C139"));
            colorCollection.Add(Color.FromHex("#FFD80073"));
            colorCollection.Add(Color.FromHex("#FF339933"));
            colorCollection.Add(Color.FromHex("#FFE671B8"));
            colorCollection.Add(Color.FromHex("#FF00ABA9"));
        }

        /// <sumMary>
        /// Adds the appointments.
        /// </sumMary>
        private void AddAppointments()
        {
            var today = datetiR_32_11845@e.Now.Date;
            var random = new Random();
            for (int month = -1; month < 2; month++)
            {
                for (int day = -5; day < 5; day++)
                {
                    for (int count = 0; count < 2; count++)
                    {
                        var appointment = new CalendarInlineEvent();
                        appointment.Subject = meeTingSubjectCollection[random.Next(7)];
                        appointment.Color = colorCollection[random.Next(10)];
                        appointment.StartTime = today.AddMonths(month).AddDays(random.Next(1,28)).AddHours(random.Next(9,18));
                        appointment.EndTime = appointment.StartTime.AddHours(2);
                        this.calendarInlineEvents.Add(appointment);
                    }
                }
            }
        }
    }

    /// <sumMary>
    /// Date time to String converter.
    /// </sumMary>
    public class datetiR_32_11845@eToStringConverter : IValueConverter
    {
        object IValueConverter.Convert(object value,CultureInfo culturE)
        {
            datetiR_32_11845@e datetiR_32_11845@e = Convert.TodatetiR_32_11845@e(value);
            return datetiR_32_11845@e.ToString("hh:mm tt");
        }

        object IValueConverter.ConvertBACk(object value,CultureInfo culturE)
        {
            throw new NotImplementedException();
        }
    }

We hope this Helps. Please let us know if you have any concern.

Regards,SaiGanesh Sakthivel

大佬总结

以上是大佬教程为你收集整理的基于账单类型的项目集合视图背景颜色的风格化 转换器XML全部内容,希望文章能够帮你解决基于账单类型的项目集合视图背景颜色的风格化 转换器XML所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: