在列表框中使用径向面板,抛出异常VisualTree单个元素

时间:2010-10-13 02:35:43

标签: wpf listbox panel itemspanel radial

我有一个非常简单的径向面板,有一些依赖属性,如下所示:

public static readonly DependencyProperty RadiusProperty = DependencyProperty.Register("Radius", typeof(double), typeof(CircularPanel), new PropertyMetadata(50.0, new PropertyChangedCallback(RadiusChanged)));

private static void RadiusChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { ((CircularPanel)sender).Refresh(); }

问题在于,每当我将此径向面板指定为列表框的itemspanel时,我都会遇到异常:

ItemsPanelTemplate的VisualTree必须是单个元素。

这就是我在XAML中设置ItemsPanel的方法:

<ItemsPanelTemplate x:Key="ItemsPanelTemplate2">
        <WpfApplication7:CircularPanel d:LayoutOverrides="Width, Height" AngleItem="{Binding Angle}" AnimationDuration="75" Radius="0" InitialAngle="90"/>
</ItemsPanelTemplate>

<ListBox ItemsPanel="{StaticResource ItemsPanelTemplate2}" ItemContainerStyle="{StaticResource ListBoxItemStyle1}" ItemsSource="{Binding Hosts, Mode=OneWay}" >

如果我删除依赖项属性的PropertyChangedCallback函数,面板可以工作,但由于我无法刷新面板,每当我更改绑定到列表框的集合时,所有项目都是相互重叠而不是循环绘制方式。这是在WPF中。我尝试过Silverlight,那里没有问题。

感谢您的帮助。感谢

1 个答案:

答案 0 :(得分:0)

相关问题