前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >WP7WrapPanel

WP7WrapPanel

作者头像
全栈程序员站长
发布2022-09-15 10:21:11
1840
发布2022-09-15 10:21:11
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

WrapPanel:这个面板控件主要是通过Orientation属性设置包含在控件是的元素从左至右或从上至下依次安排位置,当元素超过该控件边缘时,它们将会被自动转至下一行或列。此控件一般用于文本布局、拾色器、图片等。需要加载System.Windows.Controls.Toolkit.dll

WrapPanel:这个面板控件主要是通过Orientation属性设置包含在控件是的元素从左至右或从上至下依次安排位置,当元素超过该控件边缘时,它们将会被自动转至下一行或列。此控件一般用于文本布局、拾色器、图片等。需要加载System.Windows.Controls.Toolkit.dll

Xaml代码为: <Grid x:Name=”ContentPanel” Grid.Row=”1″ Margin=”12,0,12,0″> <toolkit:WrapPanel Height=”504″ HorizontalAlignment=”Left” Margin=”9,78,0,0″ Name=”wrapPanel1″ VerticalAlignment=”Top” Width=”441″ /> <Button Content=”清空” Height=”72″ HorizontalAlignment=”Left” Name=”button1″ VerticalAlignment=”Top” Width=”101″ Click=”button1_Click” /> <Button Click=”OnAdd” Content=”+1″ Tag=”1″ Height=”72″ HorizontalAlignment=”Left” Margin=”107,0,0,0″ Name=”button2″ VerticalAlignment=”Top” Width=”101″ /> <Button Click=”OnAdd” Content=”+5″ Height=”72″ HorizontalAlignment=”Left” Margin=”228,0,0,0″ Name=”button3″ Tag=”5″ VerticalAlignment=”Top” Width=”101″ /> <Button Click=”OnAdd” Content=”+8″ Height=”72″ HorizontalAlignment=”Left” Margin=”355,0,0,0″ Name=”button4″ Tag=”8″ VerticalAlignment=”Top” Width=”101″ /> </Grid> CS代码为: Random rnd = new Random(); private void button1_Click(object sender, RoutedEventArgs e) {//清空 this.wrapPanel1.Children.Clear(); } private void OnAdd(object sender, RoutedEventArgs e) {//根按按钮的Tag属性添加内容 int count = Int32.Parse((string)((FrameworkElement)sender).Tag);

while (count– > 0) { AddItem(); } }

private void AddItem() {//添加 Border b = new Border() { Width = 100, Height = 100, Background = new SolidColorBrush(Color.FromArgb(255, (byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256))), BorderThickness = new Thickness(2), Margin = new Thickness(8) };

b.BorderBrush = (SolidColorBrush)Resources[“PhoneForegroundBrush”];

//b.Tap += OnTapped;

//注册移除事件 GestureListener listener = GestureService.GetGestureListener(b); listener.Tap += new EventHandler<GestureEventArgs>(WrapPanelSample_Tap);

wrapPanel1.Children.Add(b); }

void WrapPanelSample_Tap(object sender, GestureEventArgs e) {//移除事件 Border b = (Border)sender; wrapPanel1.Children.Remove(b); }

//void OnTapped(object sender, System.Windows.Input.GestureEventArgs e) //{ // Border b = sender as Border; //if (null != b) //{ //wrapPanel.Children.Remove(b); //}

//} }

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/163304.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档