如何在Silverlight中使用Accordion.ItemTemplate时绑定AccordionItem可见性?

时间:2011-07-18 15:25:37

标签: silverlight silverlight-4.0 binding accordion visibility

手风琴项目Visibility属性可以这样绑定:

<layoutToolkit:Accordion x:Name="MyAccordion">
    <layoutToolkit:AccordionItem Visibility="{Binding IsVisible, Converter={StaticResource VisibilityConverter}}">
        ...
    </layoutToolkit:AccordionItem>
</layoutToolkit:Accordion>

但是在使用Accordion.ItemTemplate时如何绑定它?

<layoutToolkit:Accordion ItemsSource="{Binding AcordionItems}" x:Name="MyAccordion">
    <layoutToolkit:Accordion.ItemTemplate>
        <DataTemplate>
            ...
        </DataTemplate>
    </layoutToolkit:Accordion.ItemTemplate>
    <layoutToolkit:Accordion.ContentTemplate>
        <DataTemplate>
            ...
        </DataTemplate>
    </layoutToolkit:Accordion.ContentTemplate>
</layoutToolkit:Accordion>

我可以将IsVisible绑定到DataTemplate中的元素,但是会显示一个空的折叠项。我需要能够显示/隐藏整个手风琴项目。

1 个答案:

答案 0 :(得分:0)

我最终使用StackPanel和多个Accordions:

<StackPanel Orientation="Vertical">
    <ItemsControl ItemsSource="{Binding AcordionItems}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Vertical"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <layoutToolkit:Accordion Visibility="{Binding IsVisible, Converter=
                    {StaticResource VisibilityConverter}}">
                    <layoutToolkit:AccordionItem>
                        ...
                    </layoutToolkit:AccordionItem>
                </layoutToolkit:Accordion>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</StackPanel>