[英]Silverlight Toolkit Accordion in TreeView
我正在尝试获取SL Tookit(2009年3月)手风琴控件来填充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;
}
}
}
我该怎么做才能做到这一点?
您应该通过添加代码来完成代码
tv.UpdateLayout();
那应该做。
/米克
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.