博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
silverlight 后台相关代码知识点
阅读量:5042 次
发布时间:2019-06-12

本文共 2155 字,大约阅读时间需要 7 分钟。

1. Grid动态添加新的列和行。

首先添加一个Grid

<Grid x:Name="GTest" ShowGridLines="False" SizeChanged="GTest_SizeChanged" >  </Grid>

 

this.GTest.RowDefinitions.Add(new RowDefinition() {Height=new GridLength(30) });

this.GTest.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });

 

2. 为Grid动态添加Border的样式。

Border tempBorder = new Border();

tempBorder.BorderThickness = new Thickness(1);
tempBorder.BorderBrush = new SolidColorBrush(Colors.Red);
tempBorder.SetValue(Grid.ColumnProperty, 1);
tempBorder.SetValue(Grid.ColumnSpanProperty, 2);
this.GTest.Children.Add(tempBorder);

  3. 动态添加Button及Button的背景图片。

// Add new button

                Button btnNew = new Button();
                ImageBrush imageBrush = new ImageBrush();
                imageBrush.ImageSource = new BitmapImage(new Uri(@"../Images/New.gif", UriKind.Relative));
                btnNew.Background = imageBrush;
                btnNew.Width = 20;
                btnNew.Height = 20;
                btnNew.SetValue(Grid.ColumnProperty, 0);
                btnNew.SetValue(Grid.RowProperty, iContentStart);
                btnNew.Click += new RoutedEventHandler(btnNew_Click);
                titlePanel.Children.Add(btnNew);

 

4. 鼠标移动事件。

Rectangle rec = new Rectangle();

            rec.Stroke = new SolidColorBrush(Colors.Black);
            rec.Fill = new SolidColorBrush(Colors.Orange);
            rec.MouseLeftButtonDown +=new MouseButtonEventHandler(rec_MouseLeftButtonDown);
            rec.MouseLeftButtonUp += new MouseButtonEventHandler(rec_MouseLeftButtonUp);
            rec.MouseMove += new MouseEventHandler(rec_MouseMove);

 

  5, Grid的形状改变的时候,去改变Grid的类似那些Canvas控件的形状。

// First Remove the control in the Grid and ReBuild those controls that have been removed

private void GTest_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            List<UIElement> controlsToRemove = new List<UIElement>();
int RowsCount = this.GTest.RowDefinitions.Count;
for (int i = 2; i < RowsCount; i++)
            {
                controlsToRemove = (from pControl in GTest.Children
                                    where (i == (int)pControl.GetValue(Grid.RowProperty))
                                    select pControl).ToList<UIElement>();
for (int j = 0; j < controlsToRemove.Count; j++)
                {
                    GTest.Children.Remove(controlsToRemove[j]);
                }
this.GTest.RowDefinitions.Remove(this.GTest.RowDefinitions[2]);
            }
            BuildTR(postCollection);
        }

转载于:https://www.cnblogs.com/odz521/archive/2011/11/05/2237020.html

你可能感兴趣的文章
Python 拓展之推导式
查看>>
[Leetcode] DP-- 474. Ones and Zeroes
查看>>
80X86寄存器详解<转载>
查看>>
c# aop讲解
查看>>
iterable与iterator
查看>>
返回顶部(动画)
查看>>
webpack+react+antd 单页面应用实例
查看>>
Confluence 6 SQL Server 数据库驱动修改
查看>>
Confluence 6 通过 SSL 或 HTTPS 运行 - 备注和问题解决
查看>>
【47.76%】【Round #380B】Spotlights
查看>>
Git(使用码云)
查看>>
分享Java web 开发必游之路
查看>>
IIS初始化(预加载),解决第一次访问慢,程序池被回收问题(转载)
查看>>
Bean的Scope
查看>>
【BZOJ】3142: [Hnoi2013]数列
查看>>
http初探
查看>>
elasticsearch的安装
查看>>
__next__()
查看>>
爬取:中国大学排名
查看>>
聊天室(C++客户端+Pyhton服务器)_1.框架搭设
查看>>