zoukankan      html  css  js  c++  java
  • Pro Silverlight 3 in C# XAML Resources

    1. The Resources Collection

    <UserControl x:Class="EightBall.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <UserControl.Resources>
    <LinearGradientBrush x:Key="BackgroundBrush">
    <LinearGradientBrush.GradientStops>
    <GradientStop Offset="0.00" Color="Yellow" />
    <GradientStop Offset="0.50" Color="White" />
    <GradientStop Offset="1.00" Color="Purple" />
    </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>
    </UserControl.Resources>
    ...
    </UserControl>
    <Grid x:Name="grid1" Background="{StaticResource BackgroundBrush}">

    2.The Hierarchy of Resources

    <UserControl x:Class="Resources.ResourceHierarchy"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
    <StackPanel><StackPanel.Resources>
    <LinearGradientBrush x:Key="ButtonFace">
    <GradientStop Offset="0.00" Color="Yellow" />
    <GradientStop Offset="0.50" Color="White" />
    <GradientStop Offset="1.00" Color="Purple" />
    </LinearGradientBrush>
    </StackPanel.Resources>
    <Button Content="Click Me First" Margin="5"
    Background="{StaticResource ButtonFace}"></Button>
    <Button Content="Click Me Next" Margin="5"
    Background="{StaticResource ButtonFace}"></Button>
    </StackPanel>
    </Grid>
    </UserControl>

    3. Application.Resources

    <Application xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="SilverlightApplication1.App">
    <Application.Resources>
    <LinearGradientBrush x:Key="ButtonFace">
    <LinearGradientBrush.GradientStops>
    <GradientStop Offset="0.00" Color="Yellow" /><GradientStop Offset="0.50" Color="White" />
    <GradientStop Offset="1.00" Color="Purple" />
    </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>
    </Application.Resources>
    </Application>
     
    4.Accessing Resources in Code
    LinearGradientBrush brush = (LinearGradientBrush)this.Resources["ButtonFace"];
    // Swap the color order.
    Color color = brush.GradientStops[0].Color;
    brush.GradientStops[0].Color = brush.GradientStops[2].Color;
    brush.GradientStops[2].Color = color;
     
    SolidColorBrush brush = new SolidColorBrush(Colors.Yellow);
    this.Resources["ButtonFace"] = brush;

    5. Organizing Resources with Resource Dictionaries

    <ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <LinearGradientBrush x:Key="ButtonFace">
    <LinearGradientBrush.GradientStops>
    <GradientStop Offset="0.00" Color="Yellow" /><GradientStop Offset="0.50" Color="White" />
    <GradientStop Offset="1.00" Color="Purple" />
    </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>
    </ResourceDictionary>
    <Application xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="SilverlightApplication1.App">
    <Application.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="ElementBrushes.xaml" />
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    </Application.Resources>
    </Application>
    <Application.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="BasicBrushes.xaml" />
    <ResourceDictionary Source="ButtonBrushes.xaml" />
    </ResourceDictionary.MergedDictionaries>
    <LinearGradientBrush x:Key="GraphicalBrush1" ... ></LinearGradientBrush>
    <LinearGradientBrush x:Key="GraphicalBrush2" ... ></LinearGradientBrush>
    </ResourceDictionary>
    </Application.Resources>

    Book Mark:93

  • 相关阅读:
    #负分小组WEEK1#本周工作小结+下周计划
    #负分小组WEEK1#软件开发之路——需求获取与相关建模
    #负分小组WEEK1#第一次会议纪要
    #负分小组WEEK1#软件开发之路——准备阶段
    #负分小组WEEK1#确定项目——“宝宝睡吧!”儿童睡前服务服务软件+计划分工
    p6spy sql 执行记录
    apache common-lang3 工具类
    根据 ip 定位
    springcloud 与 spring boot 版本对应关系
    PowerDesign 基于mysql 数据库建模
  • 原文地址:https://www.cnblogs.com/zhanxp/p/1709403.html
Copyright © 2011-2022 走看看