zoukankan      html  css  js  c++  java
  • WPF笔记(2.9和2.10)——Layout

     2.9讲的是,如果内部设定超过容器大小,怎么办?
    StackPanel会裁剪越界部分
    DockPanel和Grid会智能判断,从而决定换行。

    2.10 自定义布局容器
    自定义容器要实现两个方法MeasureOverride和ArrangeOverride,并保证遍历其下的所有子控件,使他们都执行Measure和Arrange方法。

    using System;
    using System.Windows.Controls;
    using System.Windows;

    namespace CustomPanel {
        
    public class DiagonalPanel : Panel {

            
    protected override Size MeasureOverride( Size availableSize ) {
                
    double totalWidth = 0;
                
    double totalHeight = 0;

                
    foreach( UIElement child in Children ) {
                    child.Measure( 
    new Size( double.PositiveInfinity,
                                             
    double.PositiveInfinity ) );
                    Size childSize 
    = child.DesiredSize;
                    totalWidth 
    += childSize.Width;
                    totalHeight 
    += childSize.Height;
                }


                
    return new Size( totalWidth, totalHeight );
            }


            
    protected override Size ArrangeOverride( Size finalSize ) {
                Point currentPosition 
    = new Point( );

                
    foreach( UIElement child in Children ) {
                    Rect childRect 
    = new Rect( currentPosition, child.DesiredSize );
                    child.Arrange( childRect );
                    currentPosition.Offset( childRect.Width, childRect.Height );
                }


                
    return new Size( currentPosition.X, currentPosition.Y );
            }

        }

    }
  • 相关阅读:
    WINDOWS黑客基础(5):利用内存来进行获取计算结果
    WINDOWS黑客基础(4):查找进程运行的基址
    WINDOWS黑客基础(3):注入代码
    shell中[[]]和[]的主要区别
    sed的实际用法举例
    linux oracle profile配置
    转 -Linux 自检和 SystemTap (强大的内核调试工具)---包含下载地址
    【转】DBMS_STATS.GATHER_TABLE_STATS详解 2012-04-22 09:20:10
    Linux中的15个‘echo’ 命令实例
    BEA-WEBLOGIC ---http://www.beansoft.biz/weblogic/docs92/index.html
  • 原文地址:https://www.cnblogs.com/Jax/p/697412.html
Copyright © 2011-2022 走看看