This is a migrated thread and some comments may be shown as answers.

Overriding Default Style for AutocompleteTextBox

4 Answers 445 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
BB
Top achievements
Rank 1
BB asked on 08 Mar 2013, 05:47 PM
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!

4 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 13 Mar 2013, 11:57 AM
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.

0
James
Top achievements
Rank 1
answered on 12 Sep 2013, 08:03 PM
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.
0
Masha
Telerik team
answered on 16 Sep 2013, 12:33 PM
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 >>
0
James
Top achievements
Rank 1
answered on 16 Sep 2013, 05:54 PM
Excellent! Thanks for your help.
Tags
AutoCompleteBox
Asked by
BB
Top achievements
Rank 1
Answers by
Vladi
Telerik team
James
Top achievements
Rank 1
Masha
Telerik team
Share this question
or