1

I want to bind the SelectedDate in RadCalendar, to two CurrentDate in different RadScheduleView. How can i do that?

<telerik:RadCalendar Name="radCalendar"
    Canvas.Left="80" Canvas.Top="200" 
    Height="320" Width="400"
    SelectedDate="{Binding CurrentDate, ElementName=radScheduleView,  Mode=TwoWay}"
    SelectionMode="Single" DisplayDate="{Binding DisplayDate, Mode=TwoWay}">
</telerik:RadCalendar>

I want to have two ElementName=radScheduleView and ElementName=radScheduleView1

EDIT

here's my code that need to be bound

<telerik:RadCalendar Name="radCalendar"
     Canvas.Left="80" Canvas.Top="200" 
     Height="320" Width="400"
     SelectionMode="Single" DisplayDate="{Binding DisplayDate, Mode=TwoWay}" >

     <telerik:RadCalendar.SelectedDate>
          <MultiBinding Converter="MultiValueConverter" Mode="TwoWay">
              <Binding ElementName="radScheduleView" Path="CurrentDate"/>
              <Binding ElementName="radScheduleView1" Path="CurrentDate"/>
          </MultiBinding>
     </telerik:RadCalendar.SelectedDate>

<telerik:RadScheduleView Name="radScheduleView1" 
      Canvas.Left="60" Canvas.Top="130" 
      Height="420" Width="570"
      AppointmentsSource="{Binding Appointments}"
      SelectedAppointment="{Binding SelectedAppointment, Mode=TwoWay}"
      ActiveViewDefinitionIndex="{Binding ActiveViewDefinitionIndex,Mode=TwoWay}"
      CurrentDate="{Binding CurrentDate, Mode=TwoWay}">

      <telerik:RadScheduleView.ViewDefinitions>
         <telerik:DayViewDefinition MinorTickLength="10min" />
         </telerik:RadScheduleView.ViewDefinitions>
      </telerik:RadScheduleView>

<telerik:RadScheduleView Name="radScheduleView" 
     Canvas.Left="60" Canvas.Top="130" 
     Height="420" Width="570"
     AppointmentsSource="{Binding Appointments}"
     SelectedAppointment="{Binding SelectedAppointment, Mode=TwoWay}"
     ActiveViewDefinitionIndex="{Binding ActiveViewDefinitionIndex,Mode=TwoWay}"
     CurrentDate="{Binding CurrentDate, Mode=TwoWay}">

     <telerik:RadScheduleView.ViewDefinitions>
          <telerik:DayViewDefinition MinorTickLength="1h" />
      </telerik:RadScheduleView.ViewDefinitions>

1 Answer 1

1

You can use MultiBinding instead of simple Binding and use it with the IMultiValueConverter implementation like the following one:

public class MultiValueConverterExtension : MarkupExtension, IMultiValueConverter {
    public override object ProvideValue(IServiceProvider serviceProvider) {
        return this;
    }
    object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
        return values[1];
    }

    object[] IMultiValueConverter.ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) {
        return new object[] { value, value };
    }
}

In this case XAML will be like this one:

<telerik:RadCalendar Name="radCalendar"
    Canvas.Left="80" Canvas.Top="200" 
    Height="320" Width="400"
    SelectionMode="Single" DisplayDate="{Binding DisplayDate, Mode=TwoWay}">
    <telerik:RadCalendar.SelectedDate>
        <MultiBinding Converter="{local:MultiValueConverter}" Mode="TwoWay">
             <Binding ElementName="radScheduleView" Path="CurrentDate"/>
             <Binding ElementName="radScheduleView1" Path="CurrentDate"/>
        </MultiBinding>
    </telerik:RadCalendar.SelectedDate>
</telerik:RadCalendar>    
Sign up to request clarification or add additional context in comments.

10 Comments

@Mirza I've modified XAML in my answer to shouw you what I'm talking about
there is an error The type 'local:MultiValueConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built i set local to my namespace
@Mirza: obviously, you must define converter in resources.
Defining converter in the resources is not necessary, but this approach should work. This is a markup extension, so setter like Converter="{local:MultiValueConverter}" should be correct. Have you tried rebuilding your project? You can also use converter like <MultiBinding.Converter><local:MultiValueConverterExtension/></MultiBinding.Converter>. I also advise you to check if you declared converter in the correct namespace.
@Alexis yes its in the correct namespace i put it in code behind, now there's this error '{local:MultiValueConverter}' value is not a valid MarkupExtension expression. Cannot resolve 'MultiValueConverter' in namespace 'clr-namespace:DSSchedule'. 'MultiValueConverter' must be a subclass of MarkupExtension.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.