开发者

Problem with WPF Toolkit Calendar invoked from DataTemplate

I'm noticing a serious issue with WPF Toolkit Calendar control. It works fine if I just invoke it with normal inline XAML and set the DisplayDate to a date string, like this:

<toolkit:Calendar DisplayDate="12/6/2010"/>

However, it never honors the DisplayDate parameter when I use a DataTemplate to cause the Calendar to display. Here's an example:

<UserControl x:Class="Dashboard.Presentation.View.CalendarView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<UserControl.Resources>
    <DataTemplate DataType="{x:Type sys:DateTime}">
        <StackPanel Orientation="Vertical">
            <toolkit:Calendar DisplayDate="{Binding Path=.}" />
            <TextBlock Text="{Binding开发者_开发问答 Path=.}"/>
        </StackPanel>
    </DataTemplate>
</UserControl.Resources>
<ListBox>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.Items>
        <sys:DateTime>11/1/2010</sys:DateTime>
        <sys:DateTime>12/1/2010</sys:DateTime>
        <sys:DateTime>1/1/2011</sys:DateTime>
        <sys:DateTime>2/1/2011</sys:DateTime>
        <sys:DateTime>3/1/2011</sys:DateTime>
    </ListBox.Items>
</ListBox>

I have added a TextBlock to the DataTemplate so you can see that the Date is being bound properly, it is just not honored by the Calendar.

Is this a bug in WPF Toolkit Calendar? If so how can I get this fixed? Or is this something I'm doing wrong with DataTemplates?


Seems to be a bug with the calendar control.It resets the DisplayDate of the contol in a datatemplate somewhere before the loaded event.Any way Resetting it in the Loaded event seems to do the trick.Try this

private void Calendar_Loaded(object sender, RoutedEventArgs e)

  {

      ((Calendar)sender).DisplayDate = (DateTime) ((Calendar)sender).DataContext;

  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜