In this article we will be seeing how to create Silverlight TreeView control and add the tree view items using C#. Xaml: <sdk:TreeView/> Steps Involved: Creating a Silverlight Application:
Creating the UI: Open MainPage.xaml file and replace the code with the following one. <UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="TreeViewControl.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="Gray"> <sdk:TreeView x:Name="Menu" Height="250" Width="250"> </sdk:TreeView> </Grid> </UserControl> Using C# add the tree view items: Open MainPage.xaml.cs file and replace the code with the following code. public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); TreeViewItem item = new TreeViewItem(); item.Header = "Menu"; item.Items.Add(new TreeViewItem() { Header="Item1"}); item.Items.Add(new TreeViewItem() { Header = "Item2" }); item.Items.Add(new TreeViewItem() { Header = "Item3" }); item.Items.Add(new TreeViewItem() { Header = "Item4" }); Menu.Items.Add(item); } } Hit F5. Output:
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: