Click here to Skip to main content
15,896,111 members
Articles / Desktop Programming / WPF

WPF Treeview: Styling and Template Binding using MVVM

Rate me:
Please Sign up or sign in to vote.
4.40/5 (12 votes)
8 Aug 2011CPOL4 min read 112.7K   6K   33  
Describes how to change appearance of Treeview using custom style
<UserControl x:Class="TreeViewStyleTemplate.View.CompanyDetailView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">
            <TextBlock Text="XYZ Company"
                       Style="{DynamicResource TextBlockStyle}" />
        </Grid>
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="40" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <TextBlock Text="Department List"
                           Style="{DynamicResource TextBlockStyle}"
                           FontSize="12" />
            </Grid>
            <Grid Grid.Row="1"
                  MaxHeight="250">
                <TreeView ScrollViewer.VerticalScrollBarVisibility="Auto"
                          BorderThickness="0"
                          Background="#FFF"
                          ItemContainerStyle="{DynamicResource TreeViewItemStyle}"
                          ItemsSource="{Binding DepartmentCollection}"
                          ItemTemplate="{DynamicResource DepartmentTemplate}" />
            </Grid>
        </Grid>
    </Grid>
</UserControl>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Team Leader Reputed IT Company
India India
Having 9+ years of experience in Microsoft.Net Technology.
Experience in developing applications on Microsoft .NET Platform ( Asp.Net, WPF, Silverlight, Windows Phone 7/8).
Experience and knowledge of software design methodologies (Agile), object oriented design, and software design patterns (MVVM).
Experience in Developing android mobile application using Xamarin (mono for android) framework.

http://hirenkhirsaria.blogspot.com/

Comments and Discussions