【问题标题】:Two expanders beside each other wont expand the latter相邻的两个扩展器不会扩展后者
【发布时间】:2012-04-16 00:02:18
【问题描述】:

由于某种原因,当我将两个扩展器并排设置时,第一个扩展器似乎在第二个扩展器之后,并且不会扩展它旁边的扩展器集?有没有办法可以在下面的代码中解决这个问题?

<Grid>
    <StackPanel Orientation="Horizontal" Margin="0,0,195,0">
        <StackPanel.Triggers>
            <EventTrigger RoutedEvent="Expander.Expanded" SourceName="expander"> 
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation From="0" To="1.2" Duration="0:0:0.35" Storyboard.TargetName="listBox" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleX)"/>                                
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>
            </EventTrigger>
        </StackPanel.Triggers>
        <Expander x:Name="expander" Expanded="expander_Expanded" ExpandDirection="Right" Width="29">
                <ListBox x:Name="listBox">
                <ListBoxItem Content="ListBoxItem" VerticalAlignment="Top" />
                <ListBoxItem Content="ListBoxItem" VerticalAlignment="Top" />
                <ListBoxItem Content="ListBoxItem" VerticalAlignment="Top" />
                <ListBox.LayoutTransform>
                    <ScaleTransform ScaleX="0" ScaleY="1"/>
                </ListBox.LayoutTransform>
            </ListBox>
        </Expander>

    <StackPanel Orientation="Horizontal" Margin="0,0,342,0" Width="318">
            <StackPanel.Triggers>
                <EventTrigger RoutedEvent="Expander.Expanded" SourceName="expander1">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation From="0" To="1.2" Duration="0:0:0.35" Storyboard.TargetName="listBox1" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleX)"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </StackPanel.Triggers>
            <Expander ExpandDirection="Right" Name="expander1" Width="29">
            <ListBox Name="listBox1">
                <ListBox.LayoutTransform>
                    <ScaleTransform ScaleX="0" ScaleY="1" />
                </ListBox.LayoutTransform>
                <ListBoxItem Content="ListBoxItem" VerticalAlignment="Top" />
                <ListBoxItem Content="ListBoxItem" VerticalAlignment="Top" />
                <ListBoxItem Content="ListBoxItem" VerticalAlignment="Top" />
            </ListBox>
        </Expander>
    </StackPanel>
    </StackPanel>
</Grid>

【问题讨论】:

  • 请停止使用不相关的标签,这既不是 关于 XML 也不是 HTML。
  • 部分问题可能是使用了两个堆栈面板——为什么不只使用一个?

标签: wpf xaml layout expander


【解决方案1】:

删除Width="29"

<Expander x:Name="expander"
          Expanded="expander_Expanded"
          ExpandDirection="Right"
          Width="29">

一切都会好起来的。

【讨论】:

  • 有没有办法同时增加扩展器的大小?
  • 为什么?扩展器的大小取决于内容。正如您在 Expander.ActualWidth 属性中看到的那样,折叠和展开状态有不同的值。
  • 不抱歉,我在关闭状态下设置了扩展器的大小。
  • 我会尝试MarginPadding
猜你喜欢
  • 2015-12-20
  • 1970-01-01
  • 1970-01-01
  • 2011-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-13
相关资源
最近更新 更多