Category / Section
How to configure intellisense popup of WPF EditControl in MVVM design pattern?
6 mins read
EditControl has built-in support for IntelliSense popup, similar to the Microsoft Visual Studio text editor and you can also configure the IntelliSense popup items in MVVM design Patten by using the IntellisenseItemTemplate, IntellisenseCustomItemsSource and setting IntellisenseMode to Custom.
IntellisenseItemTemplate: This property helps to apply a custom ItemTemplate to the IntelliSense ListBox.
IntellisenseCustomItemsSource: This property helps to bind a custom ItemsSource to the IntelliSense ListBox.
IntellisenseMode: This property needs to be set to custom to apply a custom ItemsSource to IntelliSense.
The following code demonstrates the same.
ViewModel.cs
public class ViewModel
{
public ObservableCollection<Model> customItems { get; set; }
public ViewModel()
{
customItems = new ObservableCollection<Model>();
customItems.Add(new Model() { Text = "proc " });
customItems.Add(new Model() { Text = "set " });
customItems.Add(new Model() { Text = "return " });
customItems.Add(new Model() { Text = "base " });
customItems.Add(new Model() { Text = "cmd " });
customItems.Add(new Model() { Text = "Def " });
customItems.Add(new Model() { Text = "mean " });
}
}
Model.cs
public class Model : IIntellisenseItem
{
public Model()
{
}
/// <summary>
/// Gets or sets a value indicating Icon to be displayed in the IntelliSenseListBox
/// </summary>
public ImageSource Icon
{
get;
set;
}
/// <summary>
/// Gets or sets a value indicating Text to be displayed in the IntelliSenseListBox
/// </summary>
public string Text
{
get;
set;
}
/// <summary>
/// Gets or sets a collection of sub-items to be displayed
/// </summary>
public IEnumerable<IIntellisenseItem> NestedItems
{
get;
set;
}
}
MainWindow.xaml
<Window.DataContext>
<local:ViewModel />
</Window.DataContext>
<Window.Resources>
<DataTemplate x:Key="CustomIntelliSenseItemTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Text}" Grid.Column="1" />
</Grid>
</DataTemplate>
</Window.Resources>
<Grid>
<!-- Adding EditControl to application and setting its IntelliSenseMode to Auto -->
<syncfusion:EditControl
Name="EditControl1"
IntellisenseCustomItemsSource="{Binding customItems}"
IntellisenseMode="Custom"
IntellisenseItemTemplate="{StaticResource CustomIntelliSenseItemTemplate}" />
</Grid>
Conclusion
I hope you enjoyed learning about how to configure IntelliSense popup of WPF EditControl in MVVM design pattern.
You can refer to our WPF EditControl feature tour page to know about its other groundbreaking feature representations and documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!