惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Help Net Security
B
Blog RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
The Cloudflare Blog
I
InfoQ
美团技术团队
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
L
LangChain Blog
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog

博客园 - 叫什么好

为什么喜欢Kindle 如何讲故事 如何成为会讲故事的好爹妈 哈佛大学则学系课程表 认知盈余时代-知乎如何运营 决策思维 知识结构-关于基本知识和非基本的知识 IT小小鸟 2012-发现深圳 “简单”不简单 信息图表理论之—— 专业媒体数据表格设计(续) 写了一个使用代码创建Silverlight的函数 Silverlight自动根据屏幕分辨率进行布局 重新拾起遗忘近一年的Blog了 惊诧,老外的开源WIKI居然还有文言文版 如何配置禅道管理自动发送通知短信 如何通过互联网来管理多人协作的个人项目 网站写作指导方针 如何在开发中减少Bug数量
silverlight 后台相关代码知识点
叫什么好 · 2011-11-05 · via 博客园 - 叫什么好

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);
        }