WPF 手风琴垂直对齐错误

发布于 2024-09-25 08:41:51 字数 265 浏览 1 评论 0原文


使用最新 WPF 工具包中的 Accordion 控件时,我遇到了这个问题。 当手风琴控件的 VerticalAlignment 设置为“Stretch”时,如果 SelectionMode 设置为“One”,则其中包含的 AccordionItems 将不再展开。如果选择模式设置为“ZeroOrOne”,您会在多次尝试单击后得到扩展。如果将其设置为“ZeroOrMore”,则会发生一些非常时髦的事情,即手风琴项目从屏幕底部丢失!

有人找到这个问题的解决方案吗?

谢谢!

Using the Accordion control from the latest WPF toolkit i came across this issue.
When an accordion control has its VerticalAlignment set to 'Stretch' the AccordionItems contained within it will no longer expand if the SelectionMode is set to 'One'. If the selection mode is set to 'ZeroOrOne' you get expansion after several attempts at clicking. If it is set to 'ZeroOrMore' some really funky stuff happens where accordion items go missing off the bottom of the screen!

Anyone found a solution for this problem?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陈独秀 2024-10-02 08:41:51

您还可以将 Accordion SelectionSequence 属性设置为 CollapseBeforeExpand。

此错误是由于每个手风琴项的展开/折叠动画的计时问题(当展开和折叠同时发生时)造成的
Accordion 的布局更新扰乱了可扩展的大小。

You can also set the Accordion SelectionSequence property to CollapseBeforeExpand.

This bug is due to timing problems of the expanding/collapsing animation of each accordion item (when both expanding and collapsing happens simultaneously) with
the layout update of the Accordion which messes up the size available for expansion.

痴情 2024-10-02 08:41:51

一个好的解决方法是将 ActualHeightActualWidth 绑定到您希望其填充的父元素。这有点麻烦,但它会起作用。

An OK workaround is to bind the ActualHeight and ActualWidth to the parent element you want it to fill. This is a bit of a hack but it will work.

妄断弥空 2024-10-02 08:41:51

首先,我很抱歉重新激活一个非常古老的主题,但以下代码可以说明 TerrorAustralis 的响应。

第 1 部分 ScrollViewer 的 Heigth 属性取决于 Accordion 的 ActualHeigth。要进行详细调整,您可以更改 ConverterParameter 值。

<UserControl ...
         xmlns:local="clr-namespace:MyProject.namespace.converters"
         xmlns:lTk="clr-namespace:System.Windows.Controls;assembly=DotNetProjects.Layout.Toolkit">
                <lTk:Accordion HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                    <lTk:Accordion.Resources>
                        <local:RemoveMarginConverter x:Key="RemoveMarginConverter"/>
                        <Style TargetType="lTk:AccordionItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                            <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                        </Style>
                    </lTk:Accordion.Resources>
                    <lTk:AccordionItem Header="Part 1">
                        <ScrollViewer VerticalScrollBarVisibility="Auto" Background="White"
                                      Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type lTk:Accordion}},
                                                Path=ActualHeight, Converter={StaticResource RemoveMarginConverter}, ConverterParameter=px50}">
<!-- Part 1 content -->
                        </ScrollViewer>
                    </lTk:AccordionItem>
                    <lTk:AccordionItem Header="Part 2">
                        <ScrollViewer VerticalScrollBarVisibility="Auto" Background="White">
<!-- Part 2 content -->
                        </ScrollViewer>
                    </lTk:AccordionItem>
                </lTk:Accordion>
</UserControl>

和转换器的代码:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace MyProject.namespace.converters
{
    public class RemoveMarginConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var val = System.Convert.ToInt32(value);
            var margin = System.Convert.ToInt32(parameter.ToString().Replace("px", ""));
            return val - margin;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

First of all, I appologise for reactivate a very old topic but the following code can illustrate TerrorAustralis response.

The Part 1 ScrollViewer's Heigth property depends of the Accordion's ActualHeigth. To adjust in detail, you can change ConverterParameter value.

<UserControl ...
         xmlns:local="clr-namespace:MyProject.namespace.converters"
         xmlns:lTk="clr-namespace:System.Windows.Controls;assembly=DotNetProjects.Layout.Toolkit">
                <lTk:Accordion HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                    <lTk:Accordion.Resources>
                        <local:RemoveMarginConverter x:Key="RemoveMarginConverter"/>
                        <Style TargetType="lTk:AccordionItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                            <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                        </Style>
                    </lTk:Accordion.Resources>
                    <lTk:AccordionItem Header="Part 1">
                        <ScrollViewer VerticalScrollBarVisibility="Auto" Background="White"
                                      Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type lTk:Accordion}},
                                                Path=ActualHeight, Converter={StaticResource RemoveMarginConverter}, ConverterParameter=px50}">
<!-- Part 1 content -->
                        </ScrollViewer>
                    </lTk:AccordionItem>
                    <lTk:AccordionItem Header="Part 2">
                        <ScrollViewer VerticalScrollBarVisibility="Auto" Background="White">
<!-- Part 2 content -->
                        </ScrollViewer>
                    </lTk:AccordionItem>
                </lTk:Accordion>
</UserControl>

And the converter's code :

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace MyProject.namespace.converters
{
    public class RemoveMarginConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var val = System.Convert.ToInt32(value);
            var margin = System.Convert.ToInt32(parameter.ToString().Replace("px", ""));
            return val - margin;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文