首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置ControlTemplate的Itemsource

设置ControlTemplate的Itemsource
EN

Stack Overflow用户
提问于 2016-05-13 18:54:25
回答 1查看 142关注 0票数 0

我已经创建了一个AutocompleteBox,它在ControlTemplate之外运行得非常好。当我将其放置在Control模板中时,自动完成框将不再填充任何项。

代码语言:javascript
复制
<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设置为针对一个相对的祖先,我尝试了下面的方法,但是项目源还没有填充。

代码语言:javascript
复制
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:SchedulerDialog}}, Path=Atts}"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-13 19:00:38

控件模板应该是完全独立的,因此您的控件应该公开一个依赖属性(例如,称为SuggestionsSource ),自动完成框通过TemplateBinding绑定到该属性。

在使用对话框控件的地方,然后将said属性绑定到您的DataContext属性。

在您的对话类中(如果您想扩展现有控件的功能,您需要一个子类来引入属性,这里是MySchedulerDialog)。

代码语言:javascript
复制
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中:

代码语言:javascript
复制
<telerik:RadAutoCompleteBox Margin="6 0"
                            Grid.Column="1"
                            ItemsSource="{TemplateBinding SuggestionsSource}" ...>

在其中使用控件:

代码语言:javascript
复制
<local:MySchedulerDialog SuggestionsSource="{Bindings Atts}" .../>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37217407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档