wpf实现自定义布局
来源:互联网 发布:黄金时代知乎 编辑:程序博客网 时间:2024/06/05 23:04
<Window x:Class="CustomPanel.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:c="clr-namespace:CustomPanel" mc:Ignorable="d" Title="MainWindow" > <DockPanel> <TabControl DockPanel.Dock="Top" Height="130"> <TabItem> <StackPanel Orientation="Horizontal"> <GroupBox Header="Clipboard" Padding="2"> <c:RibbonPanel> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition Height="auto"/> </Grid.RowDefinitions> <Rectangle Grid.Row="0" Fill="Black" Width="20" Height="20"></Rectangle> <Label Margin="10,0" Grid.Row="1">Paste</Label> </Grid> <Rectangle Fill="Black" Width="10" Height="10" Margin="5"></Rectangle> <Rectangle Fill="Black" Width="10" Height="10"></Rectangle> <Rectangle Fill="Black" Width="10" Height="10"></Rectangle> <Rectangle Fill="Black" Width="10" Height="10"></Rectangle> <Rectangle Fill="Black" Width="10" Height="10"></Rectangle> <Rectangle Fill="Black" Width="10" Height="10"></Rectangle> </c:RibbonPanel> </GroupBox> </StackPanel> </TabItem> </TabControl> </DockPanel></Window>
using System;using System.Windows;using System.Windows.Controls;namespace CustomPanel{ public class RibbonPanel : Panel { protected override Size MeasureOverride(Size availableSize) { if (Children.Count < 1) return new Size(0, 0); UIElement firstChild = Children[0]; firstChild.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); if (Children.Count < 2) return firstChild.DesiredSize; double numRows = Math.Ceiling((Children.Count - 1) / 3d); double maxWidthForEachRemainingChild = 0; for (int i = 1; i < Children.Count; ++i) { UIElement child = Children[i]; child.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); maxWidthForEachRemainingChild = Math.Max(child.DesiredSize.Width, maxWidthForEachRemainingChild); } return new Size(firstChild.DesiredSize.Width + maxWidthForEachRemainingChild * numRows, firstChild.DesiredSize.Height); } protected override Size ArrangeOverride(Size finalSize) { if (Children.Count < 1) return finalSize; UIElement firstChild = Children[0]; Point childOrigin = new Point(0, 0); Size firstChildSize = new Size(firstChild.DesiredSize.Width, finalSize.Height); firstChild.Arrange(new Rect(childOrigin, firstChildSize)); if (Children.Count < 2) return finalSize; double numRows = Math.Ceiling((Children.Count - 1) / 3d); Size childSize = new Size((finalSize.Width - firstChildSize.Width) / numRows, finalSize.Height / 3); childOrigin.X += firstChildSize.Width; for (int i = 1; i < Children.Count; ++i) { UIElement child = Children[i]; child.Arrange(new Rect(childOrigin, childSize)); if (i % 3 == 0) { childOrigin.X += childSize.Width; childOrigin.Y = 0; } else childOrigin.Y += childSize.Height; } return finalSize; } }}
阅读全文
0 0
- wpf实现自定义布局
- WPF实现界面动态布局
- WPF ListView控件布局自定义示例
- WPF自定义控件快速构成窗体布局
- WPF自定义控件快速构成窗体布局
- WPF自定义窗体的实现
- UITableView实现自定义布局
- UITableView实现自定义布局
- 代码实现自定义布局
- WPF实现 windows自带计算机 布局
- 【WPF】Windows App 比例布局的实现
- WPF布局
- WPF布局
- WPF布局
- wpf布局
- WPF布局
- WPF 布局
- 自定义actionbar布局,实现布局复用
- 802.11协议精读2:DCF与CSMA/CA
- mailbox的client
- HashTable源码简单介绍
- 设计模式中类的关系
- HDU3397-Sequence operation
- wpf实现自定义布局
- Java-判断是否为回文数
- 折半查找
- 一个操作系统的实现笔记1:环境搭建
- 第八章 拦截器机制
- 超简单CentOS7 配置阿里云yum源
- 亚马逊EC2建立虚拟机并使用ssh连接
- JS延时函数,格1秒触发
- 人们常用的HTML5前端开发框架有哪些