Windows phone 之常用控件
一、TextBox
TextBox 显示和编辑单格式、多行文本的控件
将TextWrapping的特性设置为Wrap会使文本在到达TextBox控件的边缘时换至新行。必要时会自动扩展TextBox以便为新行留出空间
将AcceptReturn特性设置为true会导致在按换行键时插入新行,必要时会再次自动扩展TextBox以便为新行留出空间。
文本框的大小固定时,内容过多就需要添加滚动条来显示全部的内容了。
设置 HorizontalScrollBarVisibility 属性用以启动水平滚动条
设置 VerticalScrollBarVisibility 属性用以启动垂直滚动条
<phone:PhoneApplicationPage.Resources> <ResourceDictionary> <!--设置TextBox的样式--> <Style x:Key="TextBoxStyle1" TargetType="TextBox"> <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/> <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/> <Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/> <Setter Property="Foreground" Value="Blue"/> <Setter Property="BorderBrush" Value="{StaticResource PhoneTextBoxBrush}"/> <Setter Property="SelectionBackground" Value="{StaticResource PhoneAccentBrush}"/> <Setter Property="SelectionForeground" Value="{StaticResource PhoneTextBoxSelectionForegroundBrush}"/> <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/> <Setter Property="Padding" Value="2"/> </Style> </ResourceDictionary> </phone:PhoneApplicationPage.Resources>
<!--创建一个自动折行并使用上面定义的TextBoxStyle1样式资源的控件--> <TextBox Style="{StaticResource TextBoxStyle1}" Margin="12,31,22,473" Name="TextBox1" TextWrapping="Wrap" HorizontalScrollBarVisibility="Disabled" AcceptsReturn ="true" TextChanged="TextBox1_TextChanged"/> <TextBlock Height="60" HorizontalAlignment="Left" Margin="12,221,0,0" Name="textBlock1" Text="" VerticalAlignment="Top" Width="364" /> <TextBlock Height="43" HorizontalAlignment="Left" Margin="12,172,0,0" Name="textBlock2" Text="获取TextBox的输入:" VerticalAlignment="Top" Width="170" />
二、TextBlock
<!--创建一个简单的TextBlock控件--> <TextBlock x:Name="TextBlock2" Height="30" Text="你好,我是TextBlock控件" Foreground="Red" Margin="25,84,177,493"> </TextBlock> <!--给同一个TextBlock控件的文字内容设置多种不同的样式--> <TextBlock Margin="25,171,19,384"> <TextBlock.Inlines> <Run FontWeight="Bold" FontSize="14" Text="TextBlock. " /> <Run FontStyle="Italic" Foreground="Red" Text="red text. " /> <Run FontStyle="Italic" FontSize="18" Text="linear gradient text. "> <Run.Foreground> <LinearGradientBrush> <GradientStop Color="Green" Offset="0.0" /> <GradientStop Color="Purple" Offset="0.25" /> <GradientStop Color="Orange" Offset="0.5" /> <GradientStop Color="Blue" Offset="0.75" /> </LinearGradientBrush> </Run.Foreground> </Run> <Run FontStyle="Italic" Foreground="Green" Text=" green " /> </TextBlock.Inlines> </TextBlock> <!--自定义断行--> <TextBlock Margin="9,344,230,130"> 你好! <LineBreak/> 我是TextBlock <LineBreak/> 再见 <LineBreak/> --2011年6月8日 </TextBlock> <!--设置TextBlock自动折行--> <TextBlock TextWrapping="Wrap" Margin="279,344,19,154"> 好像内容太长长长长长长长长长长长长长长长长长长了 </TextBlock> <!--不设置自动折行--> <TextBlock Margin="248,477,50,77"> 好像内容太长长长长长长长长长长长长长长长长长长了 </TextBlock> <!--设置TextBlock控件内容的颜色渐变--> <TextBlock Text="颜色变变变变变变" Margin="25,519,109,21"> <TextBlock.Foreground> <LinearGradientBrush> <GradientStop Color="#FF0000FF" Offset="0.0" /> <GradientStop Color="#FFEEEEEE" Offset="1.0" /> </LinearGradientBrush> </TextBlock.Foreground> </TextBlock>
FontFamily:字体名称
FontStyle:字体样式
Width:文字区块宽度,可以赋值数字。
Height:文字区块高度,可以赋值数字。
FontWeight:thin extrallight light normal medium semibold bold extrabold black extrablack
Opacity:文字透明度,赋值为0—1.0
TextWrapping:wrap ,nowrap,wrapwithoverflow
TextBlock是没有Background这个属性的,其实这个现象也说明了一个问题,为了Windows Phone App应用的美观和统一几乎不会需要设置TextBlock的背景。
当然,如果非要设置,还是可以的,比如你可以将TextBlock控件放到一个Grid里面,控制Grid和TextBlock的Height,Width属性相同。这样可以通过设置 Grid元素的背景颜色达到修改TextBlock背景的目的。
<Grid Width="200" Height="200"> <Grid.Background> <ImageBrush ImageSource="/Image/1.png"></ImageBrush> </Grid.Background> <TextBlock Width="200" Height="200" Name="text1" Text="aa"> <TextBlock.Foreground> <ImageBrush ImageSource="/1.jpg"></ImageBrush> </TextBlock.Foreground> </TextBlock> </Grid>
三、Button
<!--使用按钮点击事件--> <Button Name="button1" Click="button1_Click" Height="72" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="46,47,0,0">事件</Button> <!--设置按钮的样式:注意未指定按钮高和宽时,HorizontalAlignment和VerticalAlignment的作用 --> <Button Name="button2" Content="样式2" FontSize="48" FontFamily="Arial Black" FontStyle="Italic" BorderBrush="Blue" BorderThickness="10" Background="Red" Foreground="Yellow" HorizontalAlignment="Center" VerticalAlignment="Center" ></Button> <!--图片按钮--> <Button Width="200" Height="200" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="61,471,195,97"> <Image Stretch="Fill" Height="176" Width="151" Source="/1.png"></Image> </Button>
当然,也可以这么写:
<!--图片按钮--> <Button Width="200" Height="200" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="61,471,195,97"> <StackPanel> <Image Stretch="Fill" Height="176" Width="151" Source="/1.png"></Image> </StackPanel> </Button>
另外,关于按钮的触发事件。
//当然,也可以指定,按钮触发的条件。 //button有三种状态。press hover release private void button1_Click(object sender, RoutedEventArgs e) { button1.ClickMode = ClickMode.Press; MessageBox.Show("测试触发状态1!"); } private void button2_Click(object sender, RoutedEventArgs e) { button2.ClickMode = ClickMode.Hover; MessageBox.Show("测试触发状态2!"); } private void button3_Click(object sender, RoutedEventArgs e) { button3.ClickMode = ClickMode.Release; MessageBox.Show("测试触发状态3!"); }
不过,,,,感觉不到差别。。。。。。不懂。。。
Windows phone 之常用控件的更多相关文章
- C语言Windows程序开发—Windows窗口样式与常用控件样式【第04天】
(一)Windows窗口(MDICLIENT)样式介绍 /* Windows窗口样式 */ WS_BORDER //带有边框的窗口 WS_CAPTION //带有标题栏的窗口 WS_CHILD //子 ...
- Windows Phone开发(11):常用控件(下)
原文:Windows Phone开发(11):常用控件(下) WP控件大部分都可以从Silverlight中继承过来,这里我也只能拿一部分作演示,对于其它控件如何使用,可以参考SDK相关说明以及Sil ...
- Windows Phone开发(10):常用控件(上)
原文:Windows Phone开发(10):常用控件(上) Windows Phone的控件有几个来源,和传统的桌面应用程序开发或Web开发一样,有默认提供的控件和第三方开者发布的控件.一般而言,如 ...
- [WinForm]WinForm跨线程UI操作常用控件类大全
前言 在C#开发的WinForm窗体程序开发的时候,经常会使用多线程处理一些比较耗时之类的操作.不过会有一个问题:就是涉及到跨线程操作UI元素. 相信才开始接触的人一定会遇上这个问题. 为了解决这个问 ...
- 【Windows编程】系列第二篇:Windows SDK创建基本控件
在Win32 SDK环境下,怎么来创建常用的那些基本控件呢?我们知道如果用MFC,简单的拖放即可完成大多数控件的创建,但是我们既然是用Windows SDK API编程,当然是从根上解决这个问题,实际 ...
- 深入Windows窗体原理及控件重绘技巧
之前有学MFC的同学告诉我觉得Windows的控件重绘难以理解,就算重绘成功了还是有些地方不明白,我觉得可能很多人都有这样的问题,在这里我从Windows窗体的最基本原理来讲解,如果你有类似的疑惑希望 ...
- WPF 10天修炼 第六天- 系统属性和常用控件
WPF系统属性和常用控件 渐变的背景色 WPF中的前景色和背景色不同于传统Winform的设置,这些属性都是Brush类型的值.在XAML中,当为这些属性设置指定的颜色后将被转换为SolidColor ...
- C# 常用控件属性及方法介绍
C#常用控件属性及方法介绍 目录 1.窗体(Form) 2.Label (标签)控件 3.TextBox ...
- VS2010/MFC编程入门之三十二(常用控件:标签控件Tab Control 上)
前面两节鸡啄米讲了树形控件Tree Control,本节开始讲解标签控件Tab Control,也可以称为选项卡控件. 标签控件简介 标签控件也比较常见.它可以把多个页面集成到一个窗口中,每个页面对应 ...
随机推荐
- C语言调用汇编实现字符串对换
1. 前面配置arm交叉编译环境. 2. 配置好qemu-arm C语言代码string-switch.c: #include <stdio.h> #include <stdlib. ...
- BWT(Burrows-Wheeler Transformation)的讲解及java实现
BWT(Burrows-Wheeler Transformation) 1.什么是BWT 压缩技术主要的工作方式就是找到重复的模式,进行紧密的编码. BWT(Burrows–Wheeler_trans ...
- InetAddress Example program in Java
The InetAddress class has no visible constructors. To create an InetAddress object, you have to use ...
- typeahead使用配置参数。
示例代码: var suggestion_source = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace( ...
- Linux下源码安装Nginx服务
nginx 安装 linux 系统需要安装必备的开发包,比如 gcc,gcc-c++ 1. openssl (支持 https) https://www.openssl.org/source/ ...
- CAS协议 - CAS URIs
http://desert3.iteye.com/blog/1703449 2.CAS URIs: CAS是一个基于HTTP的协议,这就要求其每一个组成部分可以通过特定的URIs访问到.所有相关的U ...
- 【转】SVN:Android Studio设置忽略文件
Android Studio创建的Android项目一般需要忽略 参考: http://blog.csdn.net/qq_22780533/article/details/51965007 1..id ...
- SharePoint 2013 error The given assembly name or codebase System.ServiceModel.dll was invalid
笔者近期在 SharePoint 2013 的环境中遇到一个奇怪的问题,前一天 SharePoint 2013 站点还是好好的.可是突然站点就报page can't display 500 错误: T ...
- mybatis11 sqlMapConfig.xml文件说明
1sqlMapConfig.xml SqlMapConfig.xml中配置的内容和顺序如下: properties(属性) settings(全局配置参数) typeAliases(类型别名) typ ...
- GCC扩展(转--对看kernel代码有帮助
http://my.oschina.net/senmole/blog?catalog=153878 Linux Kernel的代码,上次就发现一个结构体的定义形式看不懂,后来才知道它用的不是标准的AN ...