Overriding Default Style for AutocompleteTextBox

5 posts, 0 answers
  1. BB
    BB avatar
    3 posts
    Member since:
    Jan 2007

    Posted 08 Mar 2013 Link to this post

    In all the built in .net WPF controls, you may override the default style, and specify your own custom template.  In my usage, it allows me to view a Textbox as a Label, have a button clicked to switch the mode to Edit mode, and switch the style to change the control back to a TextBox.

    When I attempt to do the same thing for the Telerik - RadAutoCompleteTextbox, with this style, I get the following error (view mode)

    <Style x:Key="RadAutoCompleteBoxViewMode" TargetType="{x:Type telerik:RadAutoCompleteBox}">
            <Setter Property="OverridesDefaultStyle" Value="True" />
            <Setter Property="Template">
                    <ControlTemplate TargetType="{x:Type telerik:RadAutoCompleteBox}">
                        <Label Content="{Binding SearchText, RelativeSource={RelativeSource AncestorType=telerik:RadAutoCompleteBox}}" Style="{StaticResource FormFieldReadOnly}" />

    Object reference not set to an instance of an object.
       at Telerik.Windows.Controls.RadAutoCompleteBox.InitializeBoxesItemsControl() in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 1067

    Is there something I'm missing?  Is there another way to accomplish this goal ?  Should not the concept of lookless controls be supported?  

  2. Vladi
    Vladi avatar
    749 posts

    Posted 13 Mar 2013 Link to this post

    Hello Brian,

    RadAutoCompleteBox control is not a simple control and removing the entire Template of the control removes some important parts from it which are necessary in order for the control to work. In order to customize the control to make it look as a label you will need to customize the Template of the TextBoxStyle of the RadAutoCompleteBox Style and then set the BorderThickness of the AutoCompleteBox to zero.

    We created and attached a sample project for you with the described approach, hope this is helpful.

    All the best,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. James
    James avatar
    3 posts
    Member since:
    Jun 2010

    Posted 12 Sep 2013 Link to this post

    Is there a better example, perhaps one that show how to give a custom template to the RadAutoCompleteBox? I'd like to style this so that the AutoCompleteBoxesItemsControl is not inside of the search text box, however when I try to pull a copy of the style in Blend the created style with no changes has issues and does not display the drop down list.
  4. Masha
    Masha avatar
    355 posts

    Posted 16 Sep 2013 Link to this post

    Hi James,

    The issue occurs because Expression Blend is losing ItemsSource property of the RadListBox element when the template has been generated. Please add ItemsSource="{TemplateBinding FilteredItems}" to the RadListBox named PART_ListBox inside the control template of AutoCompleteBox and the drop down content will be shown.

    I hope this will be helpful.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. James
    James avatar
    3 posts
    Member since:
    Jun 2010

    Posted 16 Sep 2013 Link to this post

    Excellent! Thanks for your help.
Back to Top