在XAML中为对象属性赋值
- Attribute = Value形式
- 属性标签
- 标签扩展
//直接做内容
<Button Width="120" Height="30" />
//两个button夹杂的是内容
<Button Width="120" Height="30">
<!--Content-->
</Button>
//对象属性的内容
<Button.Content>
<Content>
</Button.Content>
按钮里弄出一个小方块(暂停按钮)
<Button Width="120" Height="30">
<Button.Content>
<Rectangle Width="20" Height="20" Stroke="DarkGreen" Fill="LawnGreen"/>
</Button.Content>
</Button>
属性标签
<Button Width="120" Height="30">
<Button.Content>
<Rectangle Width="20" Height="20" Stroke="Blue">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<!--画颜色-->
<LinearGradientBrush.GradientStops>
<!--如果是集合,可以不写标签,直接写集合内容
<GradientStopCollection>-->
<GradientStop Offset="0.2" Color="LightBlue"/>
<GradientStop Offset="0.7" Color="DarkBlue"/>
<GradientStop Offset="1.0" Color="Blue"/>
<!--</GradientStopCollection>-->
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Button.Content>
</Button>
标签扩展
<Window.Resources>
<sys:string x:Key=" stringHello">Hello WPF!</sys:string>
</Window.Resources>
<Grid>
<TextBlock Height="24" Width="120" Background="LightBlue" Text="{StaticResource ResourceKey=stringHello}"/>
</Grid>