手风琴控制仅在第二次选择后显示项目内容

时间:2011-11-01 17:12:32

标签: wpf accordion wpftoolkit

我有一个AccordionControl(WPFToolkit),我动态添加项目:

        <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,关闭它并再次打开它。这种行为可能是什么原因?

EDIT 我已经找到了一种方法,而不是使用样式,但我仍然感兴趣为什么上面的方法不起作用。这里的风格解决方案:

        <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>

EDIT 我现在发现了问题:我不能“拉伸AccordionControl。

<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>

一旦我这样做,它就不再起作用了。有人知道解决这个问题吗?

0 个答案:

没有答案