views:

497

answers:

1

I am creating a user control to display a three-month calendar. The control is based on the WPF Calendar control (WPF Toolkit 2009-06), and I want to pass several of the Calendar's properties through to corresponding properties of my user control. The user control properties are set up as Dependency Properties, and their underlying types match the types of the Calendar properties. Here is my markup:

<StackPanel>
    <toolkit:Calendar Name="MasterCalendar" 
        SelectionMode="{Binding Path=SelectionMode, Mode=OneWay}"
        SelectedDate="{Binding Path=SelectedDate, Mode=OneWayToSource}"
        SelectedDates="{Binding Path=SelectedDates, Mode=OneWayToSource}"/>
    <toolkit:Calendar Name="SlaveCalendar1" 
        DisplayDate="{Binding DisplayDate, Converter={StaticResource IncrementalMonthConverter}, ElementName=MasterCalendar, Mode=OneWay}"
        SelectionMode="{Binding Path=SelectionMode, Mode=OneWay}"
        SelectedDate="{Binding Path=SelectedDate, Mode=OneWayToSource}"
        SelectedDates="{Binding Path=SelectedDates, Mode=OneWayToSource}"/>
    <toolkit:Calendar Name="SlaveCalendar2" 
        DisplayDate="{Binding DisplayDate, Converter={StaticResource IncrementalMonthConverter}, ElementName=SlaveCalendar1, Mode=OneWay}"
        SelectionMode="{Binding Path=SelectionMode, Mode=OneWay}"
        SelectedDate="{Binding Path=SelectedDate, Mode=OneWayToSource}"
        SelectedDates="{Binding Path=SelectedDates, Mode=OneWayToSource}"/>
</StackPanel>

All of the properties bind without problem, except for the SelectedDates property. I get the following error on its binding:

'SelectedDates' property is read-only and cannot be set from markup.

I suspect that it is because the SelectedDates property is a collection, but I am not sure how to fix the problem. Can anyone enlighten me on the cause of the problem and suggest a fix? Thanks for your help.

A: 
Dabblernl
Here is where I am puzzled: If I am passing the value from, say, SlaveCalendar1 to my user control property, I am only reading SlaveCalendar1.SelectedDates; I am writing to MyUserControl.SelectedDates, which I have defined with a setter. In other words, MyUserControl.SelectedDates isn't read-only, and that's what I am writing to. Why doesn't that work?
David Veeneman
How are you passing the SlaveCalendar1.SelectedDates to this.SelectedDates? I understand you are doing it through setting the Mode of the Binding to OneWayToSource. It seems that this line of code is still interpreted as an assignment though,for which you need a setter. There are plenty workarounds!
Dabblernl
So, if I understand correctly, I can't bind a read-only property, even if the binding is OneWayToSource; that is, a binding that only reads from the read-only property? Thanks
David Veeneman