Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I started with the TreeViewWithIcon class that gives me the TreeViewItem with Icon
there is need of adding the TreeViewWithIcon dynamically in Backendcode

its ok for me , but i want to show some forms on mouseLeftButton down event that time i have not get the any action from TreeviewWithicon ,

Please help me for getting the event on selecting the TreeViewWithIcon

XML
public class TreeViewWithIcons : TreeViewItem
   {
       #region Global variables
       ImageSource iconSource;
       TextBlock textBlock;
       Image icon;
       #endregion Global variables

       #region Constructors and Destructors
       public TreeViewWithIcons()
       {
           StackPanel stack = new StackPanel();
           stack.Orientation = Orientation.Horizontal;
           Header = stack;
           //Uncomment this code If you want to add an Image after the Node-HeaderText
           //textBlock = new TextBlock();
           //textBlock.VerticalAlignment = VerticalAlignment.Center;
           //stack.Children.Add(textBlock);
           icon = new Image();
           icon.VerticalAlignment = VerticalAlignment.Center;
           icon.Margin = new Thickness(0, 0, 4, 0);
           icon.Source = iconSource;
           stack.Children.Add(icon);
           //Add the HeaderText After Adding the icon
           textBlock = new TextBlock();
           textBlock.VerticalAlignment = VerticalAlignment.Center;
           stack.Children.Add(textBlock);
       }
       #endregion Constructors and Destructors
       #region Properties
       /// <summary>
       /// Gets/Sets the Selected Image for a TreeViewNode
       /// </summary>
       public ImageSource Icon
       {
           set
           {
               iconSource = value;
               icon.Source = iconSource;
           }
           get
           {
               return iconSource;
           }
       }
       #endregion Properties
       #region Event Handlers
       /// <summary>
       /// Event Handler on UnSelected Event
       /// </summary>
       /// <param name="args">Eventargs</param>
       protected override void OnUnselected(RoutedEventArgs args)
       {
           base.OnUnselected(args);
           icon.Source = iconSource;
       }
       /// <summary>
       /// Event Handler on Selected Event
       /// </summary>
       /// <param name="args">Eventargs</param>
       protected override void OnSelected(RoutedEventArgs args)
       {
           base.OnSelected(args);
           icon.Source = iconSource;
       }

       /// <summary>
       /// Gets/Sets the HeaderText of TreeViewWithIcons
       /// </summary>
       public string HeaderText
       {
           set
           {
               textBlock.Text = value;
           }
           get
           {
               return textBlock.Text;
           }
       }
       #endregion Event Handlers
       public BitmapImage CreateImage(string path)
       {
           BitmapImage myBitmapImage = new BitmapImage();
           myBitmapImage.BeginInit();
           myBitmapImage.UriSource = new Uri(path);
           myBitmapImage.EndInit();
           return myBitmapImage;
       }
   }


Thanks and regards
vilas
Posted
Updated 4-Nov-12 22:41pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900