Articles in this section
Category / Section

How to programmatically set the Width for the Popup in the AutoComplete control?

2 mins read

Initially, the width for the popup is always smaller than the AutoComplete control width, but to initially increase the width for the popup, you can programmatically set the desired width for the popup.

To set the width for the popup in the AutoComplete control, get the popup from the AutoCompleteControl template and set the MinWidth for the popup.

The following code example illustrates how the popup for the AutoComplete is set narrower than the initial.

C#

// To programmatically set the PopUp Width in c#
public partial class MainWindow : Window
    {
        public MainWindow()
        {
          InitializeComponent();
          List<String> ProductSource = new List<String>();
          ProductSource.Add("Wpf");
          ProductSource.Add("Silverlight");
          ProductSource.Add("WindowsPhone");
          this.AutoCompleteControl.AutoCompleteSource = ProductSource;
          AutoCompleteControl.Loaded += auto1_Loaded;
        }
        void auto1_Loaded(object sender, RoutedEventArgs e)
        {
            Popup pop = AutoCompleteControl.Template.FindName("PART_Popup", AutocompleteControl) as Popup;
            if (pop != null)
            {
                pop.MinWidth = 200;          
            }
        }
    }

The following screenshot illustrates the output.

PopWidth.png

Figure 1: Popup width changed

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied