0
我试图让SL Tookit(2009年3月)Accordion控件来填充TreeView控件的ItemTemplate,但它不能正确渲染(只是一个1x1像素的方形)。Silverlight工具包TreeView中的手风琴
这里是我的XAML:
<UserControl x:Class="SilverlightTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:tkw="clr-namespace:System.Windows;assembly=System.Windows.Controls.Toolkit"
xmlns:lo="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<tk:TreeView Name="tv">
<tk:TreeView.ItemTemplate>
<DataTemplate>
<lo:Accordion Name="acc" SelectionMode="ZeroOrMore">
<lo:Accordion.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Key}"/>
</DataTemplate>
</lo:Accordion.HeaderTemplate>
<lo:Accordion.ContentTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Value: "/>
<TextBlock Text="{Binding Value}"/>
</StackPanel>
</DataTemplate>
</lo:Accordion.ContentTemplate>
</lo:Accordion>
</DataTemplate>
</tk:TreeView.ItemTemplate>
</tk:TreeView>
</Grid>
</UserControl>
而隐藏代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightTest
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
KeyValuePair<string, string>[] data = new KeyValuePair<string,string>[]
{
new KeyValuePair<string, string>("Item 1", "Apple"),
new KeyValuePair<string, string>("Item 2", "Banana"),
new KeyValuePair<string, string>("Item 3", "Grapefruit"),
new KeyValuePair<string, string>("Item 4", "Kiwi")
};
tv.ItemsSource = data;
}
}
}
我能做些什么,使这个做我想要什么?
您可以尝试使用MinHeight或MinWidth来帮助至少填写一点吗?它可能适当的大小。 – 2009-08-06 17:35:26