动态调整打开的手风琴的大小
我有一个手风琴,其内容的高度可以动态调整大小。我希望看到手风琴动态响应子项的高度,但我在执行此操作时遇到困难。
<lt:Accordion Name="MyAccordion"
SelectionMode="ZeroOrOne"
HorizontalAlignment="Stretch">
<lt:AccordionItem Name="MyAccordionItem"
Header="MyAccordion"
IsSelected="True"
HorizontalContentAlignment="Stretch"
VerticalAlignment="Stretch">
<StackPanel>
<Button Content="Grow" Click="Grow"/>
<Button Content="Shrink" Click="Shrink"/>
<TextBox Name="GrowTextBox"
Text="GrowTextBox"
Height="400"
Background="Green"
SizeChanged="GrowTextBox_SizeChanged"/>
</StackPanel>
</lt:AccordionItem>
</lt:Accordion>
private void Grow(object sender, System.Windows.RoutedEventArgs e)
{
GrowTextBox.Height += 100;
}
private void Shrink(object sender, System.Windows.RoutedEventArgs e)
{
GrowTextBox.Height -= 100;
}
private void GrowTextBox_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
{
MyAccordion.UpdateLayout();
MyAccordionItem.UpdateLayout();
}
请注意,如果我折叠然后重新打开手风琴,它就会按照我想要的方式成形,但我希望在孩子调整大小时立即进行大小调整。
我无力地尝试通过添加在 Accordion 和 AccordionItem 上调用 UpdateLayout() 的 SizeChanged 事件处理程序来解决此问题,但这没有任何视觉效果。我无法弄清楚 Accordion 控件中的适当调整大小的位置。有人有想法吗?
I have an Accordion and the height of its content can be dynamically resized. I would like to see the Accordion dynamically respond to the child item's height, but I'm having trouble doing this.
<lt:Accordion Name="MyAccordion"
SelectionMode="ZeroOrOne"
HorizontalAlignment="Stretch">
<lt:AccordionItem Name="MyAccordionItem"
Header="MyAccordion"
IsSelected="True"
HorizontalContentAlignment="Stretch"
VerticalAlignment="Stretch">
<StackPanel>
<Button Content="Grow" Click="Grow"/>
<Button Content="Shrink" Click="Shrink"/>
<TextBox Name="GrowTextBox"
Text="GrowTextBox"
Height="400"
Background="Green"
SizeChanged="GrowTextBox_SizeChanged"/>
</StackPanel>
</lt:AccordionItem>
</lt:Accordion>
private void Grow(object sender, System.Windows.RoutedEventArgs e)
{
GrowTextBox.Height += 100;
}
private void Shrink(object sender, System.Windows.RoutedEventArgs e)
{
GrowTextBox.Height -= 100;
}
private void GrowTextBox_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
{
MyAccordion.UpdateLayout();
MyAccordionItem.UpdateLayout();
}
Mind you, if I collapse and then re-open the accordion, it takes shape just the way I want, but I'd like this resizing to occur immediately when the child resizes.
I feebly attempted to fix this by adding a SizeChanged event handler that calls UpdateLayout() on the Accordion and AccordionItem, but this doesn't have any visual effect. I can't figure out where proper resizing takes place inside the Accordion control. Does anyone have an idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个
在上面的代码中,我只是根据子项目的大小重新排列手风琴。
Try this one
In the above code i am just rearranging accordion depending on child item size.
我有一个类似的问题,我的简单技巧如下:
希望它也适合你..
干杯
I have a similar problem, my simple hack is as follows:
Hope it works for you too..
Cheers
我遇到了一个稍微不同的问题 - 调整窗口大小有时无法正确调整手风琴项目的大小,因此下一个项目的标题将卡在窗口下方或中间。
我通过创建一个在 SizeChanged 中启动的计时器解决了这个问题,该计时器取消选择并立即重新选择当前项目,之后布局似乎重新调整并显示正确。也许对你也有帮助。你可以省掉计时器,我引入它是为了防止用户拖动调整窗口大小时连续调用,它还因为延迟而提供了一种羽毛效果。
I had a slightly different problem - resizing my window sometimes didn't correctly adjust the Accordion item size, so the header of the next item would be stuck below the window or in the middle of it.
I solved this by creating a timer that is started in SizeChanged, and that deselects and immediately reselects the current item, after which the layout seems to be readjusted and turns up correct. Might help you as well. You could dispense with the timer, I introduced it to prevent continuous calls when the user drag resizes the window, it also gives a kind of feathery effect because of the delay.