Basic Library for WPF and Silverlight | ComponentOne
WPF and Silverlight Edition Basic Library / TreeView / TreeView Quick Start / Step 3 of 3: Customizing the TreeView Control
In This Topic
    Step 3 of 3: Customizing the TreeView Control
    In This Topic

    In the previous step you worked in Visual Studio to create C1TreeViewItems in XAML. In this step you'll customize the C1TreeView control's appearance and behavior in Visual Studio using XAML code.

    1. Place your cursor within the <c1:C1TreeView> tag.

    Within the <c1:C1TreeView> tag add SelectionMode="Extended". This will create a top-level node that you will be able to select multiple tree items by holding the shift and control keys. The XAML markup appears as follows:

    XAML
    Copy Code
    <c1:C1TreeView x:Name="Tree" SelectionMode="Extended">
    
    1. Place your cursor within the first <c1:C1TreeViewItem> tag.

    Within the <c1:C1TreeViewItem> add the tag IsExpanded="True" and IsSelected="True". This will create a top-level node that appears selected and expanded at run time. The XAML markup appears as follows:

    XAML
    Copy Code
    <c1:C1TreeViewItem Header="Book List" IsExpanded="True" IsSelected="True">
    
    1. Locate the tag that reads <c1:C1TreeViewItem Header=" Language Books">. Within the <c1:C1TreeViewItem Header=" Language Books"> add Foreground="Fuchsia" Background="LightPink". This will add a light pink background to the “Classic Books” tree item and a fuchsia color to the text. The XAML markup will resemble the following:
    XAML
    Copy Code
    <c1:C1TreeViewItem Header="Language Books" Foreground="Fuchsia"/>
    
    1. From the Debug menu, select Start Debugging to view how your application will appear at run time. Observe the following behavioral and appearance changes for C1TreeView:

    • The C1TreeView appears expanded.
    • The first C1TreeViewItem appears selected.
    • The second C1TreeViewItem has fuchsia colored text.

    Congratulations!
    You have successfully completed the TreeView for WPF and Silverlight quick start. In this quick start, you've created and customized a TreeView for WPF or Silverlight application, added static C1TreeViewItems, and observed several of the control's run-time features.