WPF Datagrid缩放问题
我正在使用 WPFToolkit 中的 WPF DataGrid,并且在尝试缩放整个数据网格时遇到问题。 我最初的想法是,这将非常简单,我只需对网格应用缩放变换,并在用户单击按钮时为 ScaleX、ScaleY 属性设置动画。 但这不起作用,因为滚动条被放大,使其变得更大。 我需要数据网格上的固定标题和固定列,因此我不能简单地使用数据网格外部的滚动查看器来处理滚动。 我尝试的第二件事是缩放网格中的字体大小,但这失败了,因为在缩小字体大小时,列保持原始宽度并且不会缩小。
最后,我认为我可以通过使用下面的代码来工作,该代码进入数据网格的视图树并向滚动内容演示器添加比例变换。 (此代码中也未显示,我以相同的方式对标题的可视化树项应用了转换,以便它也可以缩放)。 我认为这非常有效,直到我测试了缩放后的水平滚动。 (垂直滚动效果完美。)在缩放之前,水平滚动很好,但缩放后,当我水平滚动时,显示会崩溃。 很难确切地说出它在做什么,但看起来从屏幕左侧滚动的内容正在“折叠”并返回到左侧。 也许一切都在左侧粉碎了。 有谁知道如何让这个工作正常进行,希望不要扔掉我的整个数据网格,否则它已经工作得很好。
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);
I'm working with the WPF DataGrid from the WPFToolkit and I'm having issues with trying to zoom the entire datagrid. My initial thought was that it was going to be really easy and I would just apply a scale transform to the grid and animate the ScaleX, ScaleY properties when the used clicked a button. This did not work however because the scrollbar was zoomed in making it larger. I need fixed headers and fixed columns on the datagrid so I can't simple use a scrollviewer outside of the datagrid to handle the scrolling. The second thing I tried was to just scale the font size in the grid, but this failed because on shrinking the font size the columns stay at the original width and do not shrink.
Finally I thought I had it working by using the below code which goes into the view tree for the datagrid and adds a scale transform to the Scroll Content Presenter. (Also not shown in this code, I apply a transform to the visual tree item for the headers in the same manner so that it scales as well). I thought this was working great until I tested out the horizontal scrolling after zooming. (Vertical scrolling works perfectly.) Before zooming at all the horizontal scrolling is fine, but after zooming, when I scroll horzonitally the display freaks out. It is hard to tell exactly what it is doing, but it sort of looks like the content that is scrolling off the left of the screen is "folding over" and coming back in on the left. Maybe it is just all smashing up on the left side. Does anyone have any ideas how I can get this working, hopefully without throwing out my whole datagrid that is already working quite well otherwise.
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了一个解决办法。 不知道这是否与您的做法相同:
其中 ZoomFactor 是滑块:
I figured out a solution. Don't know if this is the same way you did it or not:
Where ZoomFactor is a slider: