Silverlight TreeView 上下层属于不同表

本文介绍如何在 Silverlight 4 中使用树视图(TreeView)控件,并提供了一个示例,展示了如何通过绑定数据来构建树形结构。此示例使用 HierarchicalDataTemplate 进行数据项的模板定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://dotnetslackers.com/articles/silverlight/Using-the-TreeView-control-in-Silverlight-4.aspx

 

<UserControl x:Class="TreeViewDemo.MainPage"
     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
     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="600" d:DesignWidth="400">
    <UserControl.Resources>
        <sdk:HierarchicalDataTemplate x:Key="ContentsTemplate">
            <TextBlock FontStyle="Italic" Text="{Binding Title}"/>
        </sdk:HierarchicalDataTemplate>
        <sdk:HierarchicalDataTemplate x:Key="GenreTemplate" ItemsSource="{Binding Contents}" ItemTemplate="{StaticResource ContentsTemplate}">
                <TextBlock Text="{Binding Genre}" Margin="5,0"/>
        </sdk:HierarchicalDataTemplate>
    </UserControl.Resources>
    <Grid>
        <sdk:TreeView Margin="10,10,21,175" Name="TreeView1" ItemTemplate="{StaticResource GenreTemplate}" Background="Beige" ItemsSource="{Binding}" SelectedItemChanged="TreeView1_SelectedItemChanged"/>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="136,441,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
    </Grid>
</UserControl>

转载于:https://www.cnblogs.com/Ken-Cai/archive/2012/12/10/2810719.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值