2015-10-07 35 views
1

我想將RadCalendar中的SelectedDate綁定到不同RadScheduleView中的兩個CurrentDate。我怎樣才能做到這一點?c#wpf - 綁定到兩個ElementName

<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> 

我想有兩個ElementName=radScheduleViewElementName=radScheduleView1

編輯

這裏是我的代碼,需要綁定

<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

可以使用MultiBinding,而不是簡單的Binding並與IMultiValueConverter執行類似下面的一個使用它:

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 }; 
    } 
} 

在這種情況下,XAML會是這樣一個:

<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>  
+0

嗯,我如何在我的代碼中實現它? – Mirza

+0

@Mirza我在我的回答中修改了XAML來指責你我在說什麼 – Alexis

+0

有一個錯誤'找不到類型'local:MultiValueConverter'。驗證你是否遺漏了一個程序集引用,並且所有引用的程序集都已經構建好了,我把它設置在我的名字空間 – Mirza