XAML中Style相当于CSS,为控件提供一定的样式模板。
<phone:PhoneApplicationPage
x:Class="QYTASK.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">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.Resources>
<Style x:Key="TextBoxStyle" TargetType="TextBox">
<Setter Property="Height" Value="200"/>
<Setter Property="Foreground" Value="Blue"/>
</Style>
</Grid.Resources>
<TextBox Style="{StaticResource TextBoxStyle}" Text="Hello"></TextBox>
</Grid>
</phone:PhoneApplicationPage>
上面可以看到设置了TextBox的样式之后怎么调用这个Style,这样通过引用一次Style就不用多次设置属性了。
下面是截图: