Fork me on GitHub

xaml中资源文件的引用

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <Page.Resources>
      <SolidColorBrush x:Key="gsw" Color="Green"/>
   </Page.Resources>

  <Grid> 
     <Button Background="{StaticResource gsw}" FontSize="25"  Height="100" Width="100" >gsw</Button>
    <TextBox Grid.Row="1" Height="26" Margin="25,21,118.705,0" VerticalAlignment="Top"  Name="textBox1"  Foreground="{StaticResource gsw}">Hello</TextBox>

</Grid>
</Page>

上面是个简单的Page页。

  <Page.Resources>
      <SolidColorBrush x:Key="gsw" Color="Green"/>
   </Page.Resources>

定义了本页内一个Color的值为“Green”,它的健为“gsw”。

在接下来的代码中:

Background="{StaticResource gsw}"

Foreground="{StaticResource gsw}"

引用了刚才定义的Color,一个是背景色,一个是字体色。

效果如下:

P1

posted @ 2006-12-28 09:41  桂素伟  阅读(832)  评论(0编辑  收藏  举报