Category / Section
How to programmatically set the Width for the Popup in the AutoComplete control?
2 mins read
Initially, the width of 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 of the popup.
To set the width of the popup in the AutoComplete control, get the popup from the AutoComplete control template and set the MinWidth for the popup.
The following code example illustrates how the popup for the AutoComplete is set wider than the initial width.
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.
Figure 1: Popup width changed