Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 项目内部折叠扩展器控制WPF_C#_Wpf_Xaml - Fatal编程技术网

C# 项目内部折叠扩展器控制WPF

C# 项目内部折叠扩展器控制WPF,c#,wpf,xaml,C#,Wpf,Xaml,我在ItemsControl中显示一个扩展项列表,并将一个项列表绑定到它。 我遵循的xaml结构是 <ItemsControl ItemsSource="{Binding}" > <ItemsControl.ItemTemplate> <DataTemplate> <Expander ExpandDirection="Down" Style="{StaticResource

我在ItemsControl中显示一个扩展项列表,并将一个项列表绑定到它。 我遵循的xaml结构是

    <ItemsControl ItemsSource="{Binding}" >            
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Expander ExpandDirection="Down" Style="{StaticResource ResourceKey=ExpanderItemStyle}" >
                <Expander.Header>
                    <BulletDecorator>
                    //Expander header by default its collapsed 
                    <Label Style="{StaticResource ResourceKey=ChapterHeadStyle}"  Content="{Binding name}"></Label>                                         
                    </BulletDecorator>
                </Expander.Header>
                <StackPanel> // Expander body want to collapse it when some some other items of ItemsControl is expanded 
                </StackPanel>
            </Expander>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
当选择ItemsControl中的某些其他项时,是否可以使expander内容自动变为colpased

您可以将ItemsControl替换为ListBox,并将expander的IsExpanded属性绑定到ListBoxItem的IsSelected属性。看

您还可以将IsExpanded绑定到某个viewmodel属性并从中获取它。同样的结果也可以通过wpf行为实现


回答您的问题:不,没有自动折叠其他扩展器的方法。

IsExpanded={Binding Mode=TwoWay,Path=IsSelected,RelativeSource={RelativeSource AncestorType=ListBoxItem,Mode=FindAncestor}}这种方法对我有效,谢谢您的帮助: