如何在Windows Phone中更改RadCalendar的选定颜色?

时间:2012-07-12 06:57:52

标签: xaml c#-4.0 telerik windows-phone-7.1

我正在为我的WindowsPhone应用程序使用Telerik的RadCalendar控件。我想在WindowsPhone的RadCalendar中更改SelectedDate的背景颜色......有什么办法可以改变它吗?

1 个答案:

答案 0 :(得分:3)

您可以使用特殊模板更改SelectedDay的属性。以下是一天的示例数据模板:

<telerikInput:RadCalendar>
  <telerikInput:RadCalendar.ItemTemplate>
    <DataTemplate>
      <Grid Margin="5">
        <TextBlock Text="{Binding DetailText}" FontSize="7" MaxHeight="25" VerticalAlignment="Top" Margin="0,-2,0,0" />
        <TextBlock Text="{Binding Text}" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
      </Grid>
    </DataTemplate>
  </telerikInput:RadCalendar.ItemTemplate>
</telerikInput:RadCalendar>

周末特殊模板的示例

<?xml version="1.0" encoding="utf-8"?>
<UserControl.Resources>
  <local:WeekendDaySelector x:Key="WeekendDaySelector">
    <local:WeekendDaySelector.SpecialTemplate>
      <DataTemplate>
        <Grid Margin="5">
          <Image Source="/Calendar/Images/SpecialDay.png" Width="24" Height="24" />
          <TextBlock Text="{Binding Text}" x:Name="TextPresenter" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
        </Grid>
      </DataTemplate>
    </local:WeekendDaySelector.SpecialTemplate>
  </local:WeekendDaySelector>
</UserControl.Resources>

<telerikInput:RadCalendar ItemTemplateSelector="{StaticResource WeekendDaySelector}" />

现在是模板选择器

public class WeekendDaySelector : DataTemplateSelector
{
    public DataTemplate SpecialTemplate
    {
        get;
          set;
    }

    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        CalendarButtonContentInfo info = item as CalendarButtonContentInfo;
          CalendarButton button = container as CalendarButton;
          if (!button.IsFromCurrentView) return null;
          if (info.Date == null) return null;
          if (info.Date.Value.DayOfWeek == DayOfWeek.Saturday ||
              info.Date.Value.DayOfWeek == DayOfWeek.Sunday)
          {
               return SpecialTemplate;
          }
          return base.SelectTemplate(item, container);
    }
}

您可以在this thread了解详情。