我的问题是它是一个日历控件。我想显示来自不同颜色的服务的日期。上面显示的代码工作正常。但不是第一次。第一次加载页面时不显示具有不同颜色的日期。当发生月更改的事件时,日期将以不同的颜色显示。所以请帮我在第一个外观中显示不同颜色的日期
Xaml页面
<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>
我的c#代码
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;
}
答案 0 :(得分:1)
在传递日期对象时更改代码,如下所示: ((ColorConverter)Resources [&#34; ColorConverter&#34;])。日期=日期;
Cal.Referesh();
它对我有用......