关于WrapPanel和RadioButton相互配合使用实WrapPanel现动态添加或删除项
最近在做一个项目的时候,有一个需求就是,通过RadioButton来控制一行内容的显示与不显示,当不显示的时候,下面的项能够占住相应的位置,当增加的时候,又会在原来的位置重新显示,如果使用一般的Grid或者其它的布局的时候,位置就确定下来了,但是使用WrapPanel或者StackPanel这类的控件的时候,能够在增加或者删除项的时候实现重新布局,这在实际使用的时候是非常有用的,现总结如下:
1 <WrapPanel Grid.Column="1" Grid.Row= "1" Orientation= "Vertical" HorizontalAlignment= "Center" >
2 <StackPanel Orientation= "Horizontal" Visibility= "{Binding Path=JDBHIsVisibility, Mode=TwoWay,Converter={StaticResource BoolToVisibility Converter}}">
3 <Border BorderBrush= "Transparent" BorderThickness= "2" Height= "70" >
4 <Label Name= "lbl00" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Center" VerticalAlignment= "Center" Height= "66" Width= "300"> 警单编号:</Label>
5 </Border>
6 <Border BorderBrush = "Transparent" BorderThickness= "2" Height= "70" >
7 <Label Name= "lb_id" Content= "{Binding Path=JDBH,Mode=TwoWay}" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Left" Height= "66" Width= "715">
8 </Label>
9 </Border>
10 </StackPanel>
11 <StackPanel Orientation= "Horizontal" Visibility= "{Binding Path=BJSJIsVisibility, Mode=TwoWay,Converter={StaticResource BoolToVisibilityConverter}}">
12 <Border BorderBrush= "Transparent" BorderThickness= "2" Height= "70" >
13 <Label Name= "lbl10" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Center" VerticalAlignment= "Center" Height= "66" Width= "300"> 报警时间:</Label>
14 </Border>
15 <Border BorderBrush = "Transparent" BorderThickness= "2" Height= "70" >
16 <Label Name= "lb_time" Content= "{Binding Path=BJSJ,Mode=TwoWay}" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Left" VerticalAlignment= "Center" Height= "66" Width= "715" ></Label>
17 </Border>
18 </StackPanel>
19 <StackPanel Orientation= "Horizontal" Visibility= "{Binding Path=BJDZIsVisibility, Mode=TwoWay,Converter={StaticResource BoolToVisibilityConverter}}">
20 <Border BorderBrush= "Transparent" BorderThickness= "2" Height= "70" >
21 <Label x:Name= "lbl20" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Center" VerticalAlignment= "Center" Height= "66" Margin= "0,8" Width= "300" Content= "报警地址:"/>
22 </Border>
23 <Border BorderBrush= "Transparent" BorderThickness= "2" Height= "70" Width= "716" >
24 <Label x:Name= "lb_addr" Content= "{Binding Path=BJDZ,Mode=TwoWay}" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Left" Height= "66" Width= "715" Margin= "0,-2,-2,-2"/>
25 </Border>
26 </StackPanel>
27 <StackPanel Orientation= "Horizontal" Visibility= "{Binding Path=BJXQIsVisibility, Mode=TwoWay,Converter={StaticResource BoolToVisibilityConverter}}" >
28 <Border BorderBrush= "Transparent" BorderThickness= "2" Height= "70" >
29 <Label Name= "lbl30" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Center" VerticalAlignment= "Center" Height= "66" Margin= "0,8" Width= "300" > 报警详情:</Label>
30 </Border>
31 <Border BorderBrush = "Transparent" BorderThickness= "2" Height= "70" Width= "716" >
32 <Label x:Name= "lb_detail" Content= "{Binding Path=BJXQ,Mode=TwoWay}" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Left" Height= "66" Width= "715"/>
33 </Border>
34 </StackPanel>
35 <StackPanel Orientation= "Horizontal" Visibility= "{Binding Path=BJRIsVisibility, Mode=TwoWay,Converter={StaticResource BoolToVisibilityConverter}}">
36 <Border BorderBrush= "Transparent" BorderThickness= "2" Height= "70" >
37 <Label Name= "lbl40" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Center" VerticalAlignment= "Center" Height= "66" Width= "300" > 报 警 人:</Label>
38 </Border>
39 <Border BorderBrush = "Transparent" BorderThickness= "2" Height= "70" Margin= "0,0,10,0" >
40 <Label Name= "lb_person" Content= "{Binding Path=BJR,Mode=TwoWay}" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Left" Height= "66" Width= "715">41 42 </Label>
43 </Border>
44 </StackPanel>
45 <StackPanel Orientation = "Horizontal" Visibility= "{Binding Path=BJDHIsVisibility, Mode=TwoWay,Converter={StaticResource BoolToVisibilityConverter}}" >
46 <Border BorderBrush= "Transparent" BorderThickness= "2" Height= "70" >
47 <Label Name= "lbl50" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Center" VerticalAlignment= "Center" Height= "66" Width= "300" Margin= "0,-2"> 报警电话:</Label>
48 </Border>
49 <Border BorderBrush = "Transparent" BorderThickness= "2" Height= "70" Width= "719" >
50 <Label Name= "lb_phone" Content= "{Binding Path=BJDH,Mode=TwoWay}" Style= "{StaticResource StyleLabel}" HorizontalAlignment= "Left" Height= "66" Width= "719" Margin= "-2,-2,-2,1"/>
51 </Border>
52 </StackPanel>
53 </WrapPanel>
这里在WrapPanel中嵌套多个StackPanel,注意Visibility="{Binding Path=BJDHIsVisibility, Mode=TwoWay,Converter={StaticResource BoolToVisibilityConverter}}"> 实现的核心是,这里我们定义了一个依赖项属性BJDHIsVisibility,并且和RadioButton的IsChecked属性绑定到一起,当RadioButton选中的时候,IsChecked属性为True,我们不能直接将两个属性绑定到一起,必须去定义一个转换器,将BOOL类型的值转化为Visibility所支持的形,这里需要注意,当RadioButton的IsChecked属性为False的时候,Visibility的属性为Visibility.Hidden,此时WrapPanel会实现重新排列,这是我们需要注意的地方,以后需要的时候可以参考此值!
关于WrapPanel和RadioButton相互配合使用实WrapPanel现动态添加或删除项的更多相关文章
- Xamarin.Android 入门实例(4)之实现对 SQLLite 进行添加/修改/删除/查询操作
1.Main.axml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns: ...
- 利用JS实现在li中添加或删除class属性
$( function() { $("#test li").click(function(){ $("#test li").removeClass(" ...
- 动态添加试题选项按钮 radioButton(一)
最近在做WebView加载试题的功能,但是选项按钮如果放的WebView中,点击时反应很慢.于是把选项用原生的RadioButton,而试题题目和答案放在WebView中.但是选项的个数不确定,所以需 ...
- java线程同步实的现方式
为何要使用同步? java允许多线程并发控制,当多个线程同时操作一个可共享的资源变量时(如数据的增删改查), 将会导致数据不准确,相互之间产生冲突,因此加入同步锁以避免在该线程没有完成操作之前,被其他 ...
- RadioGroup动态添加RadioButton,并且获得事件
由于有许多的RadioButton是动态的,不是固定的一些,所以需要在代码中,动态的添加到RadioGroup中,下面是我的实现方法. 1.添加RadioButton到RadioGroup中 Radi ...
- QT中获取选中的radioButton的两种方法(动态取得控件的objectName之后,对名字进行比较)
QT中获取选中的radioButton的两种方法 QT中要获取radioButton组中被选中的那个按钮,可以采用两种如下两种办法进行: 方法一:采用对象名称进行获取 代码: 1 QRadioBu ...
- ThinkPHP框架下,jq实现在div中添加标签并且div的大小会随之变化
php初学者,有什么不对的还请指正. 首先是在html页面中用jq实现添加标签:divAchivePersonnal是select所在的div的外层div,divselectAchivePersonn ...
- ios 实现在tableViewCell上面添加长按手势 删除该条cell以及列表后台数据等
自己的代码 需要 把属性更改成自己要使用的 //创建长按手势 在cellForRowAtIndexPath代理方法中 UILongPressGestureRecognizer *longPres ...
- 鸡头兔头共20,脚56,鸡兔各有多少?算法实 php现版
//$x 鸡头 //$y 兔头 for ($x = 0; $x <= 20; $x++) { for ($y = 0; $y <= 20; $y++) { if (($x + $y == ...
随机推荐
- 素数判断-----埃氏筛法&欧拉筛法
埃氏筛法 /* |埃式筛法| |快速筛选素数| |15-7-26| */ #include <iostream> #include <cstdio> using namespa ...
- Linux kernel 之 socket 创建过程分析
重要结构体 struct socket 结构体 // 普通的 BSD 标准 socket 结构体 // socket_state: socket 状态, 连接?不连接? // type: socket ...
- C++获取单链表的倒数第k个节点
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ c ...
- Visual Studio 工具选项设置
1.显示行号 2.颜色主题 3.显示引用 一 显示行号 1)设置方式:工具-选项-文本编辑器-C#,勾选行号确定 二 颜色主题 1)设置方式:工具-选项-环境-常规,下拉选择:浅色.蓝色.深色,点确定 ...
- 【Codeforces 1105E】Helping Hiasat
Codeforces 1105 E 题意:给你m个事件,每个事件可能是以下两种之一: \(1\),代表此时可以更改用户名 \(2\) \(s\),代表\(s\)来查看是否用户名与其名字相符 一共有\( ...
- Android学习之基础知识四-Activity活动8讲(活动的灵活运用)
一.判断当前是在哪个活动 1.我们还是接着上一讲的代码,首先创建一个Java类:BaseActivity.java.这个类我们不作为一个活动,也不在AndroidManifest.xml中注册,它只是 ...
- MySQL(一)MySQL基础介绍
最近的学习内容是数据库相关的一些知识,主要以MySQL为主,参考书籍——<MySQL必知必会> MySQL学习及下载地址:https://dev.mysql.com/ MySQL学习使用注 ...
- IntelliJ IDEA常用设置(一)
一.java文件中代码有错误,不点开java文件就不提示错误解决方法,版本不同可能界面有所区别. -->File->Settings->Build,Execution,Deploym ...
- 【博客大赛】使用LM2677制作的3V至24V数控可调恒压源
[博客大赛]使用LM2677制作的3V至24V数控可调恒压源 http://bbs.ednchina.com/BLOG_ARTICLE_3013105.HTM LM2677,是TI公司生产的高效率 ...
- Newtonsoft的序列化和反序列化
class test { public string a; public int b; public byte[] c; public In ...