[Silverlight入门系列]给Toolkit的Accordion手风琴嵌入TreeView
时间:2011-06-03 来源:Mainz
Silverlight Toolkit里面提供了一个手风琴控件Accordion,如何给这个Accordion里面嵌入一个TreeView呢?就像实现这样的效果:
其实还是很简单的:
<UserControl x:Class="AccordinTreeviewTest.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"
xmlns:controls="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
d:DesignHeight="300" d:DesignWidth="400" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
<Grid x:Name="LayoutRoot" Background="White">
<toolkit:Accordion Height="236" HorizontalAlignment="Left" Margin="44,28,0,0" Name="accordion1" VerticalAlignment="Top" Width="244" >
<toolkit:AccordionItem Header="Menu 1">
<toolkit:AccordionItem.ContentTemplate>
<DataTemplate>
<controls:TreeView Margin="1" BorderThickness="0">
<controls:TreeViewItem Header="Node1">
<controls:TreeViewItem Header="Node1.1" />
<controls:TreeViewItem Header="Node1.2" />
<controls:TreeViewItem Header="Node1.3" />
</controls:TreeViewItem>
<controls:TreeViewItem Header="Node2">
<controls:TreeViewItem Header="Node2.1_testlonglonglonglonglongNode" />
<controls:TreeViewItem Header="Node2.2" />
<controls:TreeViewItem Header="Node2.3" />
</controls:TreeViewItem>
</controls:TreeView>
</DataTemplate>
</toolkit:AccordionItem.ContentTemplate>
</toolkit:AccordionItem>
<toolkit:AccordionItem Content="ontent2" Header="Menu 2"></toolkit:AccordionItem>
<toolkit:AccordionItem Content="ontent3" Header="Menu 3"></toolkit:AccordionItem>
<toolkit:AccordionItem Content="ontent4" Header="Menu 4"></toolkit:AccordionItem>
</toolkit:Accordion>
</Grid>
</UserControl>
但有个问题,那就是这个treeView不能自动Strentch,宽度和长度不能和AccordionItem的可用长度宽度一致,不能自动拉伸。下一篇解决这个问题。
相关阅读 更多 +