【问题标题】:WPF scrolling on ScaleTransform issue, multiple UI elementsWPF在ScaleTransform问题上滚动,多个UI元素
【发布时间】:2023-03-25 22:25:01
【问题描述】:

也问http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/f765d4c9-1719-4757-b467-2492d87bb4ab

全部,

我有一个在我的 WPF 应用程序中执行缩放变换的滑块。现在我遇到了一个问题,我在滚动查看器中有一个元素,该元素位于具有 Height="*" 的行内,而后续行中的另一个元素具有 Height="Auto"。

我们的目标是直到运行时我们才知道行高(甚至元素有多大),但是我们将两个元素都显示在屏幕上,第一个元素占据尽可能多的空间尽可能留出空间,底部元素始终可见,占据它需要的任何空间。

我有以下问题/解决方案声明(我认为最能描述我的问题),正如您所见,当我想实现此目标并仍然允许访问所有 UI 元素时,我不知道该怎么做缩放是否应该足够大以将其中一个元素推离屏幕(希望这是有道理的)。

Problem statement:
    ScaleTransform is causing top DG to disappear where RowDefinition Height="*"

Solution:
    Set Minimum height on RowDefinition to prevent DG from disappearing.

Problem statement:
    Setting Minimum height on RowDefinitoin causes lower rows to dissapear.

Solution:
    Add scrollviewer encapsulating grid.

Problem statement:
    Since top DG is in RowDefinition Height="*", if there is a lot of data in top DG, bottom DGs cannot be seen without scrolling.

Solution statement:
    ???

这是我当前的代码:

<Grid.RowDefinitions>
    <RowDefinition Height="*" MinHeight="120" />
    <RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<GroupBox Grid.Row="0">
    <DataGrid ItemsSource="{Binding Path=SomePathThatCouldHaveLotsOfData}">
        <!--Note that DataGrid implements its own scrollviewer as long as it's not surrounded by another scrollviewer-->
        <!--...-->
    </DataGrid>
</GroupBox>
<GroupBox Grid.Row="1">
    <!--...-->
</GroupBox>

希望大家都能理解我的问题是什么以及我想要做什么。任何想法我如何才能完成这项工作(希望以一种干净的方式)。如果有帮助,我正在使用 MVVM。

编辑:我应该指出,直到运行时我也不知道任何最大高度(并且最大高度可能无论如何都无关紧要,因为我们将使用比例变换)。

【问题讨论】:

    标签: wpf wpf-controls scrollbar scrollview wpfdatagrid


    【解决方案1】:

    全部,

    我设法实现了我的目标,但这有点丑陋的hack

    基本上,我必须捕获我的 UserControl/Page/Window 的 Loaded 和 SizeChanged 事件,并使用这些事件将 ScrollViewer.ViewPortHeight 值设置为我的 VM 中的属性。 然后,只需从中减去一个已知值作为我的最大值。 然后,只需将 ViewPortHeight 乘以我希望每个 UI 元素采用的百分比在屏幕上并将 UIs 元素绑定到它。

    希望这将帮助其他有相同业务需求的人。

    【讨论】:

      猜你喜欢
      • 2017-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      相关资源
      最近更新 更多