2016-05-13 70 views
0

我已經創建了一個AutocompleteBox,它在ControlTemplate外完全正常工作。當我將它放在Control模板中時,自動完成框不再包含任何項目。ControlTemplate的設置Itemsource

<ControlTemplate x:Key="EditAppointmentTemplate" TargetType="telerik:SchedulerDialog"> 
    <Grid Margin="6"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="97" /> 
      <ColumnDefinition Width="*" /> 
     </Grid.ColumnDefinitions> 
     <TextBlock Text="Participants" Margin="6 0" VerticalAlignment="Center" HorizontalAlignment="Left" /> 
     <telerik:RadAutoCompleteBox Margin="6 0" 
            Grid.Column="1" 
            ItemsSource="{Binding Atts}" 
            SelectedItems="{Binding SelectedAttendees,Mode=TwoWay}" 
            DisplayMemberPath="DisplayName" 
            TextSearchPath="Search" 
            Style="{StaticResource MultiAutoBox}" 
            WatermarkContent="Search ..." 
            MinHeight="55" VerticalContentAlignment="Top" Padding="5"> 
     </telerik:RadAutoCompleteBox> 
    </Grid> 
</ControlTemplate> 

<Style x:Key="EditAppointmentDialogStyle" TargetType="telerik:SchedulerDialog"> 
    .... 
    <Setter Property="Template" Value="{StaticResource EditAppointmentTemplate}" /> 
    .... 
<Style x:Key="EditAppointmentDialogStyle"/> 

<telerik:RadScheduleView x:Name="scheduleview" .... 
         EditAppointmentDialogStyle="{StaticResource EditAppointmentDialogStyle}" 
         .... 
<telerik:RadScheduleView x:Name="scheduleview"/> 

我想我已經設置的ItemsSource爲目標相對祖先 我嘗試以下和的ItemSource不填充依然。

ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:SchedulerDialog}}, Path=Atts}" 

回答

1

控制模板應該是完全獨立的,因爲這樣你的控制,應露出一個依賴屬性(稱之爲SuggestionsSource例),其中自動完成框通過TemplateBinding結合。

在您使用對話框控件的位置,然後將該屬性綁定到DataContext屬性。


在您的對話類(如果你想擴展現有控件的功能,您將需要一個子類引進性質,這裏MySchedulerDialog

public static readonly DependencyProperty SuggestionsSourceProperty = 
DependencyProperty.Register("SuggestionsSource", typeof(IList), typeof(MySchedulerDialog), new UIPropertyMetadata(null)); 
public IList SuggestionsSource 
{ 
    get { return (IList)GetValue(SuggestionsSourceProperty); } 
    set { SetValue(SuggestionsSourceProperty, value); } 
} 

在控件模板XAML:

<telerik:RadAutoCompleteBox Margin="6 0" 
          Grid.Column="1" 
          ItemsSource="{TemplateBinding SuggestionsSource}" ...> 

如果你使用控制:

<local:MySchedulerDialog SuggestionsSource="{Bindings Atts}" .../> 
+0

您能否給我一個片段或PseudoCode,以便我能更深入地理解您所指的內容? – Master

+0

@Master:你真的應該閱讀關於MSDN的控件創作,無論如何增加的例子... –

相關問題