【问题标题】:WPF Datagrid zoom issueWPF Datagrid 缩放问题
【发布时间】:2009-03-21 02:38:19
【问题描述】:

我正在使用 WPFToolkit 中的 WPF DataGrid,但在尝试缩放整个数据网格时遇到了问题。我最初的想法是这将非常简单,我只需对网格应用缩放变换,并在用户单击按钮时为 ScaleX、ScaleY 属性设置动画。但是这不起作用,因为滚动条被放大使其变大。我需要数据网格上的固定标题和固定列,所以我不能简单地使用数据网格之外的滚动查看器来处理滚动。我尝试的第二件事是仅缩放网格中的字体大小,但这失败了,因为在缩小字体大小时,列保持在原始宽度并且不会缩小。

最后,我认为我可以通过使用以下代码使其工作,该代码进入数据网格的视图树,并向 Scroll Content Presenter 添加比例变换。 (此代码中也未显示,我以相同的方式对标题的可视树项应用转换,以便它也可以缩放)。在我测试缩放后的水平滚动之前,我认为这很好用。 (垂直滚动效果很好。)在缩放之前水平滚动很好,但是在缩放之后,当我水平滚动时,显示会变坏。很难确切地说出它在做什么,但看起来像是从屏幕左侧滚动出来的内容正在“折叠”并从左侧返回。也许它只是在左侧粉碎。有没有人知道我如何才能让它工作,希望不会扔掉我已经工作得很好的整个数据网格。

 ScrollContentPresenter sp = (ScrollContentPresenter)
VisualTreeHelper.GetChild(
VisualTreeHelper.GetChild(
VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(dgMatrix,     0), 0), 0),2);
ScaleTransform st = new ScaleTransform(1, 1);
sp.LayoutTransform = st;
DoubleAnimation a = new DoubleAnimation();
a.By = 1.5;
a.AutoReverse = false;
a.Duration = new Duration(TimeSpan.Parse("0:0:0.25"));
st.BeginAnimation(ScaleTransform.ScaleXProperty, a);
st.BeginAnimation(ScaleTransform.ScaleYProperty, a);

【问题讨论】:

  • 我找到了一个可行的解决方案,一有机会就会发布。
  • 很高兴看到解决方案...我遇到了同样的问题。

标签: wpf datagrid wpftoolkit zooming


【解决方案1】:

我想出了一个解决方案。不知道你是不是这样的:

<toolkit:DataGrid.CellStyle>
    <Style TargetType="{x:Type toolkit:DataGridCell}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type toolkit:DataGridCell}">
                    <ContentPresenter>
                        <ContentPresenter.LayoutTransform>
                            <ScaleTransform ScaleX="{Binding Path=Value, ElementName=ZoomFactor}"
                                            ScaleY="{Binding Path=Value, ElementName=ZoomFactor}" />
                         </ContentPresenter.LayoutTransform>
                     </ContentPresenter>
                 </ControlTemplate>
             </Setter.Value>
         </Setter>
     </Style>
 </toolkit:DataGrid.CellStyle>

ZoomFactor 是一个滑块:

<Slider x:Name="ZoomFactor"
        Value="1"
        Minimum=".25"
        Maximum="5"
        Width="180" Margin="0,0,5,0"/>

【讨论】:

  • 我还没有完全弄清楚的唯一问题是,一旦您缩放,在您取消缩放/缩小后列不会调整大小。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-31
  • 1970-01-01
  • 1970-01-01
  • 2013-03-26
  • 2013-04-21
  • 2011-05-04
相关资源
最近更新 更多