Wpf 仅在第二次选择后显示项目内容的手风琴控件
我有一个AccordionControl(WPFToolkit),可以动态地向其中添加项目:Wpf 仅在第二次选择后显示项目内容的手风琴控件,wpf,accordion,wpftoolkit,Wpf,Accordion,Wpftoolkit,我有一个AccordionControl(WPFToolkit),可以动态地向其中添加项目: <my:Accordion Grid.Column="1" ItemsSource="{Binding Path=Tests}" SelectionMode="ZeroOrOne" HorizontalAlignment="Stretch"
<my:Accordion Grid.Column="1"
ItemsSource="{Binding Path=Tests}"
SelectionMode="ZeroOrOne"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<my:Accordion.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Header}" />
</StackPanel>
</DataTemplate>
</my:Accordion.ItemTemplate>
<my:Accordion.ContentTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Content}"/>
</DataTemplate>
</my:Accordion.ContentTemplate>
</my:Accordion>
要真正看到内容,我必须选择(打开)一个AccordionItem,关闭它,然后再次打开它。这种行为的原因可能是什么
编辑
我已经找到了一种使用样式来解决这个问题的方法,但是我仍然很感兴趣为什么上面的方法不起作用。以下是样式解决方案:
<Style x:Key="itemStyle" TargetType="my:AccordionItem">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding Header}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="accordionStyle" TargetType="my:Accordion">
<Setter Property="ItemContainerStyle" Value="{StaticResource itemStyle}" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<ItemsControl ItemsSource="{Binding MenuItems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Text, Mode=OneWay}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<my:Accordion Grid.Column="1" Height="Auto"
Name="accordion1"
ExpandDirection="Left"
SelectionMode="One"
ItemsSource="{Binding Tests}"
Style="{StaticResource accordionStyle}">
</my:Accordion>
编辑
我现在发现了问题:我无法“拉伸手风琴控件”
<my:Accordion Grid.Column="1" Height="Auto"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Name="accordion1"
ExpandDirection="Left"
SelectionMode="One"
ItemsSource="{Binding Tests}"
Style="{StaticResource accordionStyle}">
</my:Accordion>
一旦我这么做了,它就不起作用了。有人知道怎么解决这个问题吗