Unable to set a StyleSelector for MonthCalendar Items in DateTimeEditBox

Editors for WPF Forum

Posted 12 years ago by Josh Luth - Software Developer, Esha Research
Version: 12.1.0560
Platform: .NET 4.0
Environment: Windows 7 (64-bit)
Avatar

I've been working with the MonthCalendar control with reasonable success even though it lacks good MVVM support. But I went to use the DateTimeEditBox and it seems the same stuff I've been using for the MonthCalendar control does not work. I'm attempting to Bind the StyleSelectors for DayItem, MonthItem, YearItem, and DecadeItem and my binding seems to be being ignored.

 

<UserControl ...>
<UserControl.Resources> 
   <Style x:Key="DateTimeEditBoxStyle" TargetType="{x:Type editors:DateTimeEditBox}">
      <Style.Triggers>
         <Trigger Property="DefaultDropDownContentType" Value="MonthCalendar">
            <Setter Property="DropDownContentTemplate">
               <Setter.Value>
                  <DataTemplate>
                     <editors:MonthCalendar BorderThickness="0" 
                                            SelectedDate="{Binding DateValue, RelativeSource={RelativeSource 
                                                                AncestorType={x:Type editors:DateTimeEditBox}}}"
                                            Style="{Binding MonthCalendarStyle, RelativeSource={RelativeSource 
                                                                AncestorType={x:Type editors:DateTimeEditBox}}}"
                                            FirstDayOfWeek="Sunday" 
                                            CalendarWeekRule="FirstDay" 
                                            DayOfWeekFormatPattern="Full" 
                                            cal:Message.Attach="[Event SelectionChanged] = [Action OnSelectDate]"
                                            DayItemStyleSelector="{Binding DayStyleSelector}"
                                            MonthItemStyleSelector="{Binding MonthStyleSelector}"
                                            YearItemStyleSelector="{Binding YearStyleSelector}"
                                            DecadeItemStyleSelector="{Binding DecadeStyleSelector}">
                     </editors:MonthCalendar>
                  </DataTemplate>
               </Setter.Value>
            </Setter>
         </Trigger>
      </Style.Triggers>
   </Style>
</UserControl.Resources> 

<Grid>
   <editors:DateTimeEditBox DateValue="{Binding SelectedDate}"
                            Format="MM/dd/yyyy"
                            Style="{StaticResource DateTimeEditBoxStyle}"/>  
</Grid> 
</UserControl> 

 

As you can see from the above code, the DayItemStyleSelector is bound a property in my ViewModel. The "get" never gets hit which tells me the binding is incorrect. I use a very similar chunk of code, but only the MonthCalendar part in another View/ViewModel and it works just fine. What am I missing?

Comments (2)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Josh,

It sounds like the DataContext isn't passing down to the popup perhaps.  Could you do a binding similar to the one for SelectedDate where you look for the DateTimeEditBox ancestor and then look at its DataContext.DayItemSelector, etc. property?


Actipro Software Support

Answer - Posted 12 years ago by Josh Luth - Software Developer, Esha Research
Avatar

You sir are a genius. For others having this sort of issue. I added this property to my MonthCalendar:

DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type editors:DateTimeEditBox}}}"
The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.