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

  • 相关阅读:
    堆排序
    append、appendTo、prepend、prependTo、before、insertBefore、after、insertAfter、replaceAll方法被调用后,原本在页面上显示的元素会消失
    jQuery中的 $.ajax的一些方法
    attr VS prop 区别
    Canvas---clearRect()清除圆形区域
    HTML5 FormData方法介绍
    MongoDB学习笔记——数据库的创建与初始
    es6学习---.babelrc文件
    【转载】基于webpack构建react项目
    node常用模块---path
  • 原文地址:https://www.cnblogs.com/zhanxp/p/1709403.html
Copyright © 2011-2022 走看看