StaticResource

内部定义

<phone:PhoneApplicationPage.Resources>
  <Style x:Key="color" TargetType="TextBlock">
    <Setter Property="FontSize" Value="20"></Setter>
  </Style>
  <Style x:Key="font" TargetType="TextBox">
    <Setter Property="Background" Value="Blue"></Setter>
  </Style>
  <BitmapImage UriSource="/Icons/20130601210710.jpg" x:Key="logo"></BitmapImage>
</phone:PhoneApplicationPage.Resources>

外部定义[app.xaml]

<Application.Resources>
<BitmapImage UriSource="/Icons/20130601210710.jpg" x:Key="logo1"></BitmapImage>
<BitmapImage UriSource="/Icons/20130605085539.jpg" x:Key="logo2"></BitmapImage>
<BitmapImage UriSource="/Icons/appbar.back.rest.png" x:Key="logo3"></BitmapImage>
<BitmapImage UriSource="/Icons/appbar.cancel.rest.png" x:Key="logo4"></BitmapImage>
<Style x:Key="aaa" TargetType="TextBox">
<Setter Property="Height" Value="550"></Setter>

</Style>
</Application.Resources>

调用

<Image Height="150" HorizontalAlignment="Left" Margin="182,87,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" DataContext="{Binding}" Source="{StaticResource logo1}" />

<Image Height="150" HorizontalAlignment="Left" Margin="182,287,0,0" Name="image2" Stretch="Fill" VerticalAlignment="Top" Width="200" DataContext="{Binding}" Source="{StaticResource logo2}" Grid.RowSpan="2" />
<TextBlock Style="{StaticResource color}" Height="147" HorizontalAlignment="Left" Margin="10,10,0,0" Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" Width="166" />
<TextBox Style="{StaticResource aaa}" HorizontalAlignment="Left" Margin="6,113,0,0" Name="textBox1" Text="TextBox" VerticalAlignment="Top" Width="460" />

原文地址:https://www.cnblogs.com/yuluhuang/p/3316854.html