我正在尝试使用SL Tookit(2009年3月)Accordion控件来填充TreeView控件的ItemTemplate,但它无法正确渲染(只有1x1像素的正方形)。
这是我的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;
}
}
}
我能做些什么才能做到我想做的事?
答案 0 :(得分:1)
你应该通过添加
来完成代码tv.UpdateLayout();
应该这样做。
/ Micke