This example illustrates how to display a custom appointment field value (see How to: Create a Custom Field for an Appointment) in the appointment rectangle. We override the appointment template for this purpose in the following manner:
[XAML]<DataTemplatex:Key="{dxscht:SchedulerViewThemeKey ResourceKey=VerticalAppointmentContentTemplate}"><GridSnapsToDevicePixels="True"HorizontalAlignment="Stretch"VerticalAlignment="Stretch"Background="Transparent"> ...<TextBlockText="{Binding CustomViewInfo.Price, StringFormat={}{0:C2}}"Foreground="Red"TextTrimming="CharacterEllipsis"/> ...</Grid></DataTemplate>
To pass a custom field value via the CustomViewInfo, handle the SchedulerControl.AppointmentViewInfoCustomizing Event as follows:
[C#]privatevoidschedulerControl1_AppointmentViewInfoCustomizing(objectsender,AppointmentViewInfoCustomizingEventArgse){CustomAppointmentDatacad=newCustomAppointmentData();objectprice=e.ViewInfo.Appointment.CustomFields["cfPrice"];if(price!=null&&price!=DBNull.Value)cad.Price=Convert.ToDecimal(price);e.ViewInfo.CustomViewInfo=cad;}
The CustomAppointmentData class is defined as follows:
[C#]publicclassCustomAppointmentData:DependencyObject{publicstaticreadonlyDependencyPropertyPriceProperty=DependencyProperty.Register("Price",typeof(decimal),typeof(CustomAppointmentData),newPropertyMetadata(0m));publicdecimalPrice{get{return(decimal)GetValue(PriceProperty);}set{SetValue(PriceProperty,value);}}}
Note that this approach is also used in the "Appointment Customization" demo module (see Demos in Installation). In addition, the HorizontalAppointmentContentTemplate in this demo is customized. It affects the appointment appearance in views other than Day and Work Week.
Here is a screenshot that illustrates a sample application in action:
See Also:
How to display custom tooltips for appointments, resource headers and date headers