1 out of 1 rated this helpful - Rate this topic

AutoCompleteBox.TextBoxStyle Property

Silverlight

Gets or sets the Style applied to the text box portion of the AutoCompleteBox control.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Input (in System.Windows.Controls.Input.dll)
public Style TextBoxStyle { get; set; }
<sdk:AutoCompleteBox TextBoxStyle="staticResourceReference"/>

XAML Values

staticResourceReference

A reference to an existing Style resource in a resource dictionary.

Property Value

Type: System.Windows.Style
The Style applied to the text box portion of the AutoCompleteBox control. The default is null.

The following example shows how to set a custom style for the TextBoxStyle and the ItemContainerStyle properties. This code example requires a reference to the System.Windows.Controls.Input assembly.

Run this sample


myACB.ItemsSource = new String[]{"London", "Paris", 
    "Johannesburg", "Bucharest", "Berlin", "Lisbon","New York", 
    "Nairobi", "Seattle", "Mexico City", "Vancouver"};



<Border BorderBrush="DarkGray" BorderThickness="2">
    <StackPanel x:Name="LayoutRoot" Background="LightYellow" Orientation="Vertical">
        <TextBlock Margin="5" Text="TextBoxStyle and ItemContainerStyle Example" />
        <StackPanel Orientation="Horizontal">
             <StackPanel.Resources>
                    <Style  x:Key="myTBStyle" TargetType="TextBox">
                    <Setter Property="Background" Value="LightYellow" />
                    <Setter Property="Foreground" Value="DarkSlateGray" />
                    <Setter Property="Margin" Value="5" />
                    <Setter Property="FontWeight" Value="Bold" />
                    <Setter Property="FontSize" Value="14" />
                    <Setter Property="BorderBrush" Value="DarkGray" />
                </Style>
                <Style  x:Key="myLBStyle" TargetType="ListBoxItem">
                    <Setter Property="Background" Value="Khaki" />
                    <Setter Property="Foreground" Value="DarkSlateGray" />
                    <Setter Property="Margin" Value="5" />
                    <Setter Property="FontStyle" Value="Italic" />
                    <Setter Property="FontSize" Value="14" />
                    <Setter Property="BorderBrush" Value="DarkGray" />
                </Style>
            </StackPanel.Resources>
            <TextBox Height="30" Width="Auto" IsReadOnly="True" Text="Enter city:" 
                Style="{StaticResource myTBStyle}" BorderBrush="LightGray" />
            <sdk:AutoCompleteBox Width="150"  Height="30" x:Name="myACB" 
                TextBoxStyle="{StaticResource myTBStyle}" 
                ItemContainerStyle="{StaticResource myLBStyle}" />
        </StackPanel>
    </StackPanel>
</Border>


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Example is working for TextAlignment
I've tried the above example on an AutoCompleteBox in Silverlight, and the style seemed to have no effect. I was particularly trying to set the text alignment because if the selected text is longer than the control you only get the end of the text not the beginning. HorizontalContentAlignment also had no effect.