[Windows Phone学习笔记]UserControl的使用
UserControl的使用
开发过程中,多个UI控件需要协同工作,相互交互之后,才可完成一个完整的业务需求,此时可把这些控件封装成为一个整体,相互之间的交互逻辑封装其中,外部调用可无需
关心内部逻辑,只需获取处理后的结果即可
创建UserControl步骤如下:
1.创建xaml布局,UserControl外观,创建UIs
2.在对应.cs文件中添加内部业务逻辑代码
ex:
创建一个带TextBlock的Button
1.xaml布局文件TextBlockButton.xaml
<UserControl x:Class="UserControlTest.UserControls.TextBlockButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480"> <Grid x:Name="LayoutRoot"
Background="{StaticResource PhoneChromeBrush}">
<StackPanel>
<TextBlock Name="textBlock"
HorizontalAlignment="Center"
Text="textBlock"/>
<Button Name="btn"
Content="Button"/>
</StackPanel>
</Grid>
</UserControl>
TextBlockButton
2..cs代码
public partial class TextBlockButton : UserControl
{
// 步长
public int Step { get; set; } public TextBlockButton()
{
InitializeComponent(); this.btn.Click += btn_Click;
} void btn_Click(object sender, RoutedEventArgs e)
{
this.textBlock.Text = (Step++) + "";
}
}
TextBlockButton.xaml.cs
3.使用UserControl
a).引入UserControl
b).获得引用
在需要使用的页面添加引用
<phone:PhoneApplicationPage
x:Class="UserControlTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True" xmlns:userControls="clr-namespace:UserControlTest.UserControls"
> <!--LayoutRoot 是包含所有页面内容的根网格-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions> <!--TitlePanel 包含应用程序的名称和页标题-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="页面名称" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel> <!--ContentPanel - 在此处放置其他内容-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel>
<userControls:TextBlockButton Name="textBlockBtn"
Step="0"/>
</StackPanel>
</Grid>
</Grid> </phone:PhoneApplicationPage>
MainPage.xaml
在MainPage.xaml.cs文件中通过name属性可以引用UserControl
[Windows Phone学习笔记]UserControl的使用的更多相关文章
- Windows Security 学习笔记
对于Windows 在 Security 方面的学习. 纯兴趣. UNIX 的另外开一条路线学习. 话说今天查gpedit.msc的资料的时候发现 M$ 官网上怎么连个文档都没有. 后来才点了 gpe ...
- Windows程序设计学习笔记(一)Windows内存管理初步
学习Windows程序设计也有一些时间了,为了记录自己的学习成果,以便以后查看,我希望自己能够坚持写下一系列的学习心得,对自己学习的内容进行总结,同时与大家交流.因为刚学习所以可能有的地方写不不正确, ...
- Windows Internals学习笔记(八)IO系统
参考资料: 1. <Windows Internals> 知识点: ● 当一个进
- Windows Internals学习笔记(七)Image Loader
参考资料: 1. <Windows Internals> 2. Fibers 知识点: ● 当一个进程在系统上启动时,内核将创建一个进程对象来代表它,并执行各种内核相关的初始化任务.然而, ...
- Windows Internals学习笔记(六)Windows关键系统组件
参考资料: 1. <Windows Internals> 2. Dependency Walker 3. Ntoskrnl.exe 4. Livekd的使用 5. WinDbg的使用(一) ...
- Windows调试学习笔记:(二)WinDBG调试.NET程序示例
好不容易把环境打好了,一定要试试牛刀.我创建了一个极其简单的程序(如下).让我们期待会有好的结果吧,阿门! using System; using System.Collections.Generic ...
- Windows调试学习笔记:(一)WinDBG中加载SOS和CLR
最近产品环境出现了部分服务器当机情况,虽然重启之后问题就不出现了.但本着彻底解决问题的态度,想要找到root cause.多次尝试Visual Studio失败(可能是代码惊醒了优化和签名)之后,决定 ...
- Windows Internals学习笔记(五)Synchronization
参考资料: 1. <Windows Internals> 2. 自旋锁spinlock剖析与改进 3. Lock指令前缀 4. Lock指令前缀(二) 5. Kernel Dispatch ...
- Windows Internals学习笔记(四)Trap Dispatching
参考资料: 1. <Windows Internals> 知识点: ● 陷阱trap:它是一种处理器机制,用以在某一异常或中断出现时,捕捉该执行线程,并将其控制权转交到操作系统中某一固定位 ...
随机推荐
- 安卓开发06:布局-线性布局 LinearLayout
LinearLayout把视图组织成一行或一列.子视图能被安排成垂直的或水平的.线性布局是非常常用的一种布局方式. 请看一个布局例子: <LinearLayout xmlns:android=& ...
- 项目优化经验分享(六)SVN冲突和处理
上一篇博客我们分享了新增需求的确定思想<站在全局看问题>.今天我们来分享项目开发中SVN冲突的解决经验:SVN冲突和处理! 引言 开发过项目的人都知道,公司开发一个项目都会使用到版本号控制 ...
- 数据备份--dump(此作者有许多有用的博客文章)
数据中 心操作大量的数据.当遭到破坏时,这就是一场灾难.这时候需要备份来恢复,及时你又大量的备份数据都没用,备份也肯定不是在浪费时间.你也许很幸运从 来没有经历过数据丢失.但是, 由于这种事情极少发生 ...
- EL显示List里嵌套map(Spring MVC3)返回的model
<c:forEach items="${requestScope.courseList}" var="cMap" varStatus="stat ...
- JAVA面试中问及HIBERNATE与 MYBATIS的对比,在这里做一下总结(转)
hibernate以及mybatis都有过学习,在java面试中也被提及问道过,在项目实践中也应用过,现在对hibernate和mybatis做一下对比,便于大家更好的理解和学习,使自己在做项目中更加 ...
- Struts 2最新0day破坏性漏洞(远程任意代码执行)等的重现方法
Struts 2的远程任意代码执行和重定向漏洞,是这两天互联网上最重大的安全事件,据说国内互联网企业中,很多电商纷纷中招,应该已经有大规模的用户隐私泄露.这里我们简单总结下怎样在自己机子上重现这些漏洞 ...
- 控件风格19种,必须倒背如流——其实就是控件所拥有的能力,即有条件使用VCL框架所提供的(功能)代码
{ New TControlStyles: csNeedsBorderPaint and csParentBackground. These two ControlStyles are only ap ...
- Axure基础系列教程
Axure rp 6.5的软件安装.汉化与注册 认识Axure的软件界面 生成网页原型的三种方法 如何关闭IE浏览器在生成原型时候的安全警告 在chrome中使用axure生成原型的问题 站点地图 ...
- 基于visual Studio2013解决面试题之0709求方
题目
- [置顶] C++之TinyXML的使用介绍
一.引子: 最近在做GBT28181国标平台对接的工作,涉及到一些进程间消息通讯,消息体有xml格式,之前测试的时候都是拿他们当做字符串去解析,现在正儿八经地开发的时候,就想到了用xml库去解析,由于 ...