Windows Phone 自定义布局控件,继承Panel
2011-05-30 09:23
330 查看
自定义布局控件
01: using System; 02: using System.Net; 03: using System.Windows; 04: using System.Windows.Controls; 05: using System.Windows.Documents; 06: using System.Windows.Ink; 07: using System.Windows.Input; 08: using System.Windows.Media; 09: using System.Windows.Media.Animation; 10: using System.Windows.Shapes; 11: 12: namespace Demos7 13: { 14: public class CellsPanel:Panel 15: { 16: //重写测量方法 17: protected override Size MeasureOverride(Size availableSize) 18: { 19: int i = 0; 20: foreach (FrameworkElement child in Children) 21: { 22: if (i < 15) 23: { 24: //为前15个可放在这个容器中的元素分配100×100的空间 25: child.Measure(new Size(100, 100)); 26: } 27: else 28: { //15个之后的呢,就不显示了。 29: child.Measure(new Size(0, 0)); 30: } 31: i++; 32: } 33: return new Size(300,600);//总大小 34: } 35: 36: //重写排列方法 37: protected override Size ArrangeOverride(Size finalSize) 38: { 39: UIElementCollection mychildren = Children; //Children 是Panel父类的共有成员 40: int count = mychildren.Count; 41: for (int i = 0; i < count; i++) //遍历每一个成员 42: { 43: Point cellOrigin = GetCellOrigin(i);//计算左上角的位置 44: double dw = mychildren[i].DesiredSize.Width;//宽度值 45: double dh = mychildren[i].DesiredSize.Height;//高度值 46: mychildren[i].Arrange(new Rect(cellOrigin.X, cellOrigin.Y, dw, dh));//排列元素的位置及他的宽度和高度 47: } 48: return new Size(300, 600); 49: } 50: 51: //计算索引为cellIndex的子元素的左上角位置 52: protected Point GetCellOrigin(int cellIndex) 53: { 54: int cellRow, cellColomn; 55: cellColomn = cellIndex % 3; 56: cellRow = cellIndex / 3; 57: 58: int x, y; 59: x = cellColomn * 100; 60: y = cellRow * 100; 61: if (cellColomn == 1) y += 50; 62: 63: Point cellOrigin = new Point(x, y); 64: return cellOrigin; 65: } 66: 67: } 68: }
相关文章推荐
- Windows Phone 自定义布局控件,继承Panel
- Windows Phone 自定义布局控件,继承Panel
- Android 之自定义布局(继承控件)
- windows phone:Expression Blend实例中文教程(5) - 布局控件快速入门StackPanel,ScrollViewer和Border
- c#学习笔记之使用 TableLayoutPanel 控件设置窗体布局
- 实现TextView可最多两行显示、右边控件紧跟TextView效果自定义布局
- [Windows Phone] StackPanel和Grid在布局中的使用
- [Ext.Net] 1.2.0_在程序集中自定义 TreePanel 控件
- Silverlight:利用Panel实现自定义布局
- Android利用布局实现伪自定义商品数量加减控件
- Windows Phone 7 使用Canvas Grid StackPanel进行布局管理
- Android开发学习之路--UI之自定义布局和控件
- WPF的ListView控件自定义布局用法实例
- activePDF Architect WBE 控件可动态产生自定义PDF文件,控制布局和页面元素
- ExtJs4 笔记(9) Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件
- C#学习日记2016-12-26 TableLayoutPanel控件以及页面布局
- wpf之布局控件stackpanel、wrappanel、dockpanel的前世今生
- (转)自定义一个控件继承基类usercontrol,但是不能输入中文
- 继承RelativeLayout 自定义布局
- java.lang.ClassCastException: android.widget.ListView 替换控件出错 如自定义mlistview继承listview