Silverlight / WPF - Add icon in wpf textbox - Asked By Lokesh M on 20-Feb-12 12:05 AM

Hi,

Is there anyway to insert an icon in wpf textbox.

trying to insert "Lock" icon to an extreme left of the password textbox.

Thanks.
Somesh Yadav replied to Lokesh M on 20-Feb-12 12:09 AM
Hi in Windows Forms Tree View the process of adding the icons was very similar. TreeView control provides the ImageList property. A custom list of images can be directly attached to this property. Below is the small sample of code, I have taken this idea from one of the blogs in MSDN:

//Create a Root Node for TreeView
treeView.Nodes.Add("RootNode");
//Create Child Nodes for TreeView
TreeNode rootNode = treeView.Nodes[0];
rootNode.Nodes.Add("A");
rootNode.Nodes.Add("A");
rootNode.Nodes.Add("A");
rootNode.Nodes.Add("A");
rootNode.ExpandAll();
//Create an Imagelist
ImageList imageList = CreateImageList();
//Add the ImageList to TreeView
treeView.ImageList = imageList;
//Set the Starting Image Index
treeView.ImageIndex = 1;

For more information refer to the below link.

http://www.codeproject.com/Articles/25458/Add-Icons-in-WPF-Tree-View

Hope it helps you.
Anoop S replied to Lokesh M on 20-Feb-12 01:10 AM

For achieving this functionality you have to put an Image into your XAML code with Source binding to a Dependency Property. Then during the KeyboardPreview event you can changing the Dependency Property in order to display the image you want.

Finally you can create your your own UserControl