Floating FB sharing byReview Results

Floating FB sharing byReview Results

  • WPF Tutorial

    • # Read in Your Language


    WPF Controls

    Tutorial Home | Layouts | Containers | Button | CheckBox and CheckedListBox | ComboBox | DateTimePicker and MonthCalendar | DataGrid | Label and LinkLabel | ListBox | ListView | TextBox and MaskedTextBox| PictureBox and ProgressBar | TreeView | WebBrowser | Menus,Status and Toolbar | RadioButton | RichTextBox | ToolTip and Scrolling | Custom Controls

    TreeView control in WPF

    TreeView:

    Namespace : System.Windows.Controls.TreeView

    Designer Code:

    
         <TreeView Margin="10,10,0,13" Name="TreeView1" HorizontalAlignment="Left" 
         VerticalAlignment="Top" Width="194" Height="200">
                <TreeViewItem Header="WPF">
                    <TreeViewItem Header="Databinding"></TreeViewItem>
                    <TreeViewItem Header="Controls"></TreeViewItem>
                    <TreeViewItem Header="Containers"></TreeViewItem>
                    <TreeViewItem Header="Milk"></TreeViewItem>
                </TreeViewItem>
         </TreeView>
            

    Code Behind:

    
            // Window1.xaml.cs
    private void TreeView1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) { TreeViewItem Tvi = (TreeViewItem)TreeView1.SelectedItem; } adding Items from code: TreeViewItem tvi = new TreeViewItem(); tvi.Header = Databinding; Parent.Items.Add(newChild); Removing Items from Listbox: TreeView1.Items.RemoveAt (TreeView1.Items.IndexOf(TreeView1.SelectedItem));




    This is a ItemsControl.


    Images in a TreeView:
    
         <TreeView Margin="10,10,0,0" Name="TreeView1" HorizontalAlignment="Left" 
         VerticalAlignment="Top" Width="196" Height="227" 
            SelectedItemChanged="TreeView1_SelectedItemChanged">
                <TreeViewItem Header="WPF">
                   <TreeViewItem Name="DataBinding">
                        <TreeViewItem.Header>
                            <StackPanel Orientation="Horizontal">
                                <Image Source="Images\win2wpf.JPG" 
                                Height="30"></Image>
                                <TextBlock Text="1"></TextBlock>
                            </StackPanel>
                        </TreeViewItem.Header>
                    </TreeViewItem>
                    <TreeViewItem Name="Controls">
                        <TreeViewItem.Header>
                            <StackPanel Orientation="Horizontal">
                                <Image Source="Images\win2wpf.JPG" 
                                Height="30"></Image>
                                <TextBlock Text="2"></TextBlock>
                            </StackPanel>
                        </TreeViewItem.Header>
                    </TreeViewItem>
                </TreeViewItem>
          </TreeView>
            



    CheckBoxes in a Treeview:

    For adding checkboxes in treeview use the following code:

    
         <TreeView Margin="10,10,0,0" Name="TreeView1" HorizontalAlignment="Left" 
         VerticalAlignment="Top" Width="196" Height="227" 
            SelectedItemChanged="TreeView1_SelectedItemChanged">
                <TreeViewItem Header="WPF">
                   <TreeViewItem Name="DataBinding">
                        <TreeViewItem.Header>
                            <StackPanel Orientation="Horizontal">
                              <CheckBox Content="DataBinding" />
                            </StackPanel>
                        </TreeViewItem.Header>
                    </TreeViewItem>
                    <TreeViewItem Name="Controls">
                        <TreeViewItem.Header>
                            <StackPanel Orientation="Horizontal">
                              <CheckBox Content="Controls" />
                            </StackPanel>
                        </TreeViewItem.Header>
                    </TreeViewItem>
                </TreeViewItem>
          </TreeView>
            




    << Previous >> | << Next >>