[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:它是一种处理器机制,用以在某一异常或中断出现时,捕捉该执行线程,并将其控制权转交到操作系统中某一固定位 ...
随机推荐
- cocos2d-x游戏开发系列教程-中国象棋03-主界面
前情回顾 上个博客说道我们象棋程序进入了欢迎界面,在欢迎界面下等待一秒进入主界面 进入主界面的关键代码如下: CCScene* pScene = CCMainMenu::scene(); 创建sce ...
- 初探 插头DP
因为这题,气得我火冒三丈! 这数据是不是有问题啊!我用cin代替scanf后居然就AC了(本来一直卡在Test 18)!导致我调(对)试(排)了一个小时!! UPD:后来细细想想,会不会是因为scan ...
- .NET支持上下左右移动操作
效果如下图: 代码如下: public partial class ShowSet : System.Web.UI.Page { Hashtable resources = EquStatusSear ...
- 获取CPU序列号
public string GetCPUSerialNo() { string cpuSerialNo = string.Empty; ManagementClass managementClass ...
- 配置SAP 采购合同审批
需求: 采购合同类型是MK,采购组织是POSC,采购组PGC,标识:估计价格是空,总价有值0.00 - 9999999999.00 RMB 满足以上条件的时候需要审批该合同. 配置: spro-> ...
- Java基础12 类型转换与多态
链接地址:http://www.cnblogs.com/vamei/archive/2013/04/01/2992662.html 作者:Vamei 出处:http://www.cnblogs.com ...
- Linux服务器使用SSH的命令(有详细的参数解释)
前一阵远程维护Linux服务器,使用的是SSH,传说中的secure shell. 登陆:ssh [hostname] -u user 输入密码:***** 登陆以后就可以像控制自己的机器一样控制它了 ...
- QT的动态翻译功能,可能依赖于消息(事件)机制
QTranslator translator; bool b = translator.load(QString(":/qm/lang_en"));以后,无论使用QObject的t ...
- Java引用详解
区分几个概念 ,类 .对象 .对象的引用 A a1 = new A(); A a2 = a1; a1-------------------->对象内存<---------------- ...
- POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)
Gone Fishing Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 30281 Accepted: 9124 Des ...