当前位置:编程学习 > C#/ASP.NET >>

WPF的窗口,如何整合地调整大小和位置?

this.WindowLeft = l;
this.WindowTop = t;
this.Width = w;
this.Height = t;

到底有没有上面代码的整合版?例如类似:

this.setLocation(x, y, w, h); --------------------编程问答-------------------- this.Margin = new Thickness(0, 10, 0, 0); --------------------编程问答-------------------- 对于控件,这个才有用。
对于窗口,这个是没有用的。


引用 1 楼 lijunhu1 的回复:
this.Margin = new Thickness(0, 10, 0, 0);
--------------------编程问答--------------------
引用 2 楼 u011299171 的回复:
对于控件,这个才有用。
对于窗口,这个是没有用的。


Quote: 引用 1 楼 lijunhu1 的回复:

this.Margin = new Thickness(0, 10, 0, 0);

这个好像没有提供进行一次性设置的方法。 --------------------编程问答-------------------- 是微软故意不提供这个函数?

引用 3 楼 lijunhu1 的回复:
Quote: 引用 2 楼 u011299171 的回复:

对于控件,这个才有用。
对于窗口,这个是没有用的。


Quote: 引用 1 楼 lijunhu1 的回复:

this.Margin = new Thickness(0, 10, 0, 0);

这个好像没有提供进行一次性设置的方法。
--------------------编程问答-------------------- 没有  自己封装个呗   --------------------编程问答-------------------- 你不明白我的意思。

引用 5 楼 coobai 的回复:
没有  自己封装个呗  
--------------------编程问答--------------------
引用 4 楼 u011299171 的回复:
是微软故意不提供这个函数?

Quote: 引用 3 楼 lijunhu1 的回复:

Quote: 引用 2 楼 u011299171 的回复:

对于控件,这个才有用。
对于窗口,这个是没有用的。


Quote: 引用 1 楼 lijunhu1 的回复:

this.Margin = new Thickness(0, 10, 0, 0);

这个好像没有提供进行一次性设置的方法。

这就不清楚了,自己封装个是个不错的办法。 --------------------编程问答--------------------
引用 6 楼 u011299171 的回复:
你不明白我的意思。

Quote: 引用 5 楼 coobai 的回复:

没有  自己封装个呗  

扩展方法。 --------------------编程问答-------------------- 自己封装有什么用?
自己封装的话,效率上是很低的。

例如,windows的api,setWindowPos()可以一次性的设置top,left,width,height四个值。

而自己封装的话,其实是调用了4次setWindowPos(),

this.WindowLeft = l;  //这里会调用一次setWindowPos
this.WindowTop = t;   //这里会调用一次setWindowPos
this.Width = w;       //这里会调用一次setWindowPos
this.Height = t;      //这里会调用一次setWindowPos --------------------编程问答-------------------- 你怎么就知道wpf会调用四次setWindowPos呢?至少我看不到这个断言的出处。 --------------------编程问答-------------------- 可能你在所谓winform、GDI+编程的那种习惯里,写惯了那种手工低级的、不知道异步和自动将几十个(类似)setWindowPos方法仅自动执行一次的系统设计。但是wpf不会是这样的,因为我们大量地使用零散的单独设置属性的方法,而wpf仍然很快、没有反复刷新。 --------------------编程问答--------------------
你能否分析一下,为什么下面的代码,窗口的右边界和下边界,会出现抖动的情况?

按代码的逻辑,右边界和下边界是应该不动的:因为每一次changeWindowPos后,右边界的x坐标,和下边界的y坐标,并没有变化。

你有否办法解决这个?






        void changeWindowPos(double x, double y, double w, double h)
        {
            this.WindowLeft = x;
            this.WindowTop = y;
            this.WindowWidth = w;
            this.WindowHeight = h;
        }


        void changePosAnimation()
        {
            for (int i = 0; i < 100; i++)
            {
                if (i % 2 == 0)
                {
                    double x = this.WindowLeft + 100;
                    double y = this.WindowTop + 100;
                    double w = this.WindowWidth - 100;
                    double h = this.WindowHeight - 100;
                    changeWindowPos(x, y, w, h);
                }
                else
                {
                    double x = this.WindowLeft - 100;
                    double y = this.WindowTop - 100;
                    double w = this.WindowWidth + 100;
                    double h = this.WindowHeight + 100;
                    changeWindowPos(x, y, w, h);
                }
            }
        }





引用 11 楼 sp1234 的回复:
可能你在所谓winform、GDI+编程的那种习惯里,写惯了那种手工低级的、不知道异步和自动将几十个(类似)setWindowPos方法仅自动执行一次的系统设计。但是wpf不会是这样的,因为我们大量地使用零散的单独设置属性的方法,而wpf仍然很快、没有反复刷新。
--------------------编程问答-------------------- 这个动画,可能会更清晰的看到右边界和下边界的抖动:

有没有办法解决?





        void changeWindowPos(double x, double y, double w, double h)
        {
            this.WindowLeft = x;
            this.WindowTop = y;
            this.WindowWidth = w;
            this.WindowHeight = h;
        }


        void changePosAnimation()
        {
            for (int i = 0; i < 100; i++)
            {
                double x = this.WindowLeft + 2;
                double y = this.WindowTop + 2;
                double w = this.WindowWidth - 2;
                double h = this.WindowHeight - 2;
                changeWindowPos(x, y, w, h);
            }
        }




引用 11 楼 sp1234 的回复:
可能你在所谓winform、GDI+编程的那种习惯里,写惯了那种手工低级的、不知道异步和自动将几十个(类似)setWindowPos方法仅自动执行一次的系统设计。但是wpf不会是这样的,因为我们大量地使用零散的单独设置属性的方法,而wpf仍然很快、没有反复刷新。
--------------------编程问答-------------------- 或者可以试用一下调用系统setWindowPos()。
但不一定有用,因为setWindowPos并没有改变上层的属性值。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,