我已经创建了一个AutocompleteBox,它在ControlTemplate之外运行得非常好。当我将其放置在Control模板中时,自动完成框将不再填充任何项。
<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设置为针对一个相对的祖先,我尝试了下面的方法,但是项目源还没有填充。
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:SchedulerDialog}}, Path=Atts}"发布于 2016-05-13 19:00:38
控件模板应该是完全独立的,因此您的控件应该公开一个依赖属性(例如,称为SuggestionsSource ),自动完成框通过TemplateBinding绑定到该属性。
在使用对话框控件的地方,然后将said属性绑定到您的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}" .../>https://stackoverflow.com/questions/37217407
复制相似问题