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">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type telerik:RadAutoCompleteBox}">
                        <Label Content="{Binding SearchText, RelativeSource={RelativeSource AncestorType=telerik:RadAutoCompleteBox}}" Style="{StaticResource FormFieldReadOnly}" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    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?  

    thanks!
  2. Vladi
    Admin
    Vladi avatar
    744 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,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. 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.
  5. Masha
    Admin
    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.


    Regards,
    Masha
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    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 >>
  6. 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
UI for WPF is Visual Studio 2017 Ready