Arun.P
Arun.P

Reputation: 163

How to change the color of multiple days in wp8 calendar control

My issue is it is a calendar control.I want to show dates which comes from services with different color.The code which was above displayed works fine .But not for the first time.For the first time when page is loaded it doesn't display dates with different color.When an event occurs that is month change then the dates are displayed with different color. So please help me to show dates with different color in the first apperance

Xaml page

    <local:ColorConverter x:Key="ColorConverter"/>
</phone:PhoneApplicationPage.Resources>
            <Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
                    <wpControls:Calendar 
            x:Name="Cal"
ColorConverter="{StaticResource ColorConverter}"
            MonthChanged="Cal_MonthChanged"
            MonthChanging="Cal_MonthChanging"
            SelectionChanged="Cal_SelectionChanged"
            EnableGestures="True"
            />
              </Grid>
</Grid>

My c# code

 private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
    {
        StringBuilder postData = new StringBuilder();
        postData.AppendFormat("{0}={1}", "apikey", HttpUtility.UrlEncode("ETG123"));
        postData.AppendFormat("&{0}={1}", "pageen", HttpUtility.UrlEncode("1"));

        WebClient wc = new WebClient();
        wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
        wc.UploadStringAsync(new Uri("http://192.168.0.149/xxxxx/Services/get_events", UriKind.Absolute), "POST", postData.ToString());
        wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
 }

    string SS;
    DateTime start;
    List<DateTime> dates = new List<DateTime>();
    void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
    {


cd =JsonConvert.DeserializeObject<Calendarcontrol>(e.Result);
        var KK = cd.Event.ToList();
 //Events k =  (KK)[0];

        foreach (Events k in KK)
 {
   SS = k.startdate;
   start = DateTime.Parse(SS);
   dates.Add(start);
 }
                    ((ColorConverter)Resources["ColorConverter"]).Dates = dates;
    }

Upvotes: 1

Views: 170

Answers (1)

Jeet
Jeet

Reputation: 26

Change your code at passing dates objects as under: ((ColorConverter)Resources["ColorConverter"]).Dates = dates;

Cal.Referesh();

It worked for me...

Upvotes: 1

Related Questions