使用StaticResource给控件定义公共的样式和属性来写界面XAML
一:效果图
二:定义公共的样式和属性
在MainPage.xaml中
<phone:PhoneApplicationPage.Resources>
<SolidColorBrush x:Key="MyBrush" Color="Brown"/>
<Style TargetType="Button" x:Key="MyButtonBackground">
<Setter Property="Background" Value="Blue"/>
</Style>
</phone:PhoneApplicationPage.Resources>
在App.xaml中,下划线部分
<!--应用程序资源-->
<Application.Resources>
<local:LocalizedStrings xmlns:local="clr-namespace:XAMLResources" x:Key="LocalizedStrings"/>
<Style x:Name="MyTitleText"
BasedOn="{StaticResource PhoneTextBlockBase}"
TargetType="TextBlock">
<Setter Property="FontFamily"
Value="Verdana"/>
<Setter Property="FontSize"
Value="64"/>
</Style>
</Application.Resources>
MainPage.xaml的全部代码
<phone:PhoneApplicationPage
x:Class="XAMLResources.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"> <phone:PhoneApplicationPage.Resources>
<SolidColorBrush x:Key="MyBrush" Color="Brown"/>
<Style TargetType="Button" x:Key="MyButtonBackground">
<Setter Property="Background" Value="Blue"/>
</Style>
</phone:PhoneApplicationPage.Resources> <!--LayoutRoot 是包含所有页面内容的根网格-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions> <!--TitlePanel 包含应用程序的名称和页标题-->
<StackPanel x:Name="TitlePanel" Grid.Row="" Margin="12,17,0,28">
<TextBlock Text="红马車" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock
Text="hongmaju"
Margin="9,-7,0,0" Style="{StaticResource MyTitleText}"/>--------------使用了App.xaml中定义公共样式
</StackPanel> <!--ContentPanel - 在此处放置其他内容-->
<StackPanel x:Name="ContentPanel" Grid.Row="" Margin="12,0,12,0">
<Button
Height=""
Width=""
Background="{ StaticResource MyBrush }" >
</Button>
<Button
Height=""
Width=""
Style="{StaticResource MyButtonBackground}">
</Button>
<ListBox
Height=""
Width=""
Background="{StaticResource MyBrush}"> </ListBox> </StackPanel>
</Grid> </phone:PhoneApplicationPage>
三:将定义的公共样式和属性直接使用在相应控件位置的快捷方式(如下图)
使用StaticResource给控件定义公共的样式和属性来写界面XAML的更多相关文章
- grootJS ui控件定义
index13.html <html><head> <title>ui控件定义</title> <script src="jquery- ...
- WPF 绑定StaticResource到控件的方法
原文:WPF 绑定StaticResource到控件的方法 资源文件内的属性能否直接通过绑定应用到控件?答案是肯定的. 比如,我们要直接把下面的<SolidColorBrush x:Key=&q ...
- Xamarin.Forms XAML控件的公共属性
Xamarin.Forms XAML控件的公共属性 Xamarin.Forms XAML控件有很多.通过官网API,可以查看每个控件的属性.但是官网只给出了控件的特有属性,而公共属性没有列出.所以 ...
- firedac数据集控件的公共祖先类——TFDAdaptedDataSet
firedac数据集控件的公共祖先类——TFDAdaptedDataSet TFDQuery = class(TFDCustomQuery)TFDCustomQuery = class(TFDRdbm ...
- WPF滑块控件(Slider)的自定义样式
前言 每次开发滑块控件的样式都要花很久去读样式代码,感觉有点记不牢,所以特此备忘. 自定义滑块样式 首先创建项目,添加Slider控件. 然后获取Slider的Window样式,如下图操作. 然后弹出 ...
- MFC的组合框(ComboBox)控件切换下拉样式
由于课题的需求需要做MFC串口程序,看了百度下载的串口助手的界面风格,发现这个设计很好 波特率的组合框只给出了5个可选数值,然后第6个选项是Custom,即手动输入. 实际上DCB结构的BaudRat ...
- 设置DataGridView控件中字体的样式
实现效果: 知识运用: DataGridView控件的公共属性DefaultCellStyle的Font属性 public Font Font {get;set;} //获取或设置应用与DataGr ...
- .net 控件开发第二天 怎么将 第一天写的代码 用到 .net中来
前面第一天 我们看到的全是 js的代码,虽然不管是BS的框架是java 还是 php,复用性 还是特别高的, 但是 写起来比较费劲,怎么办,我们能不能 更 简单点呢? 当然可以,这个时候我们就要用到 ...
- 036——VUE中表单控件处理之动态绑定文章的属性的处理方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- Codeforces 231E - Cactus
231E - Cactus 给一个10^5个点的无向图,每个点最多属于一个环,规定两点之间的简单路:从起点到终点,经过的边不重复 给10^5个询问,每个询问两个点,问这两个点之间有多少条简单路. 挺综 ...
- HTML设置固定页脚飘浮
Css /* 页脚 */.footSty{bottom: 0pt; margin: 0pt; position: fixed; width: 100%; z-index: 10 ! important ...
- Axiom3D学习日记 2.介绍SceneManager,SceneNode,Entity
SceneManager(场景管理类) 所有出现在屏幕里的东西都受SceneManager管理(最好是这样),当你放置对象在场景里,SceneManager就会跟踪他们的位置,当你为场景创建一个相机, ...
- CentOS 5.4下的Memcache安装步骤(Linux+Nginx+PHP+Memcached)
原文链接:http://www.jb51.net/article/29668.htm
- SimpleDateFormat使用详解
http://blog.csdn.net/gubaohua/article/details/575488 public class SimpleDateFormat extends DateForma ...
- Android平台的四大天王:Activity, Service, ContentProvider, BroadcastReceiver
今天开始要自学android,刚看到百度知道上面这段话,觉得不错(不过已经是2011年8月的回答了): Android系统的手机的每一个你能看到的画面都是一个activity,它像是一个画布,随你在上 ...
- Linq 调试
void Main() { var MyMonitor = new Devart.Data.Oracle.OracleMonitor(); MyMonitor.IsActive = true; var ...
- iOS NSData简单解析
iOS 基本数据类型之NSData 1 nsdata 作用: 用于存储二进制的数据类型 nadat类提供一种简单的方式,它用来设置缓存区.将文件的内容读入到缓存区.或者将缓存区中的内容写到一个文件. ...
- spl_autoload_register()和__autoload()
关于spl_autoload_register()和__autoload() 看两者的用法: //__autoload用法 function __autoload($classname) { ...
- JS作用域概念-预解析规则
// 作用域: // 域:空间.范围.区域…… // 作用:读.写 script 全局变量.全局函数 自上而下 函数 由里到外 {} 浏览器: “JS解析器” 1)“找一些东西” :var funct ...