zoukankan      html  css  js  c++  java
  • SilverLight 样式与模板

    1. ContentPresenter 与ItemsPresenter

    <Style TargetType="HeaderedItemsControl">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type HeaderedItemsControl}">
            <StackPanel>
              <Grid>
                <Rectangle Fill="{TemplateBinding Background}"/>
                <ContentPresenter ContentSource="Header"/>
              </Grid>
              <Grid>
                <Rectangle Stroke="{TemplateBinding BorderBrush}"/>
                <ItemsPresenter Margin="2,0,0,0"/>
              </Grid>
            </StackPanel>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    1. ItemsPanelTemplate


    <Style TargetType="ListBox">
        <Setter Property="ItemsPanel">
          <Setter.Value>
            <ItemsPanelTemplate>
              <StackPanel Orientation="Horizontal"
                          VerticalAlignment="Center"
                          HorizontalAlignment="Center"/>
            </ItemsPanelTemplate>
          </Setter.Value>
        </Setter>
      </Style>

    1. DataTemplate

    Style Resource 定义:

    <DataTemplate x:Key="myTaskTemplate">
      <StackPanel>
        <TextBlock Text="{Binding Path=TaskName}" />
        <TextBlock Text="{Binding Path=Description}"/>
        <TextBlock Text="{Binding Path=Priority}"/>
      </StackPanel>
    </DataTemplate>

    使用:

    <ListBox Width="400" Margin="10"
             ItemsSource="{Binding Source={StaticResource myTodoList}}"
             ItemTemplate="{StaticResource myTaskTemplate}"/>

    二、进阶

    1.Trigger & EventTrigger

    <Style TargetType="ListBoxItem">
      <Setter Property="Opacity" Value="0.5" />
      <Setter Property="MaxHeight" Value="75" />
      <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Opacity" Value="1.0" />
        </Trigger>


    ...


      </Style.Triggers>
    </Style>


    <Style TargetType="Rectangle">
      <Setter Property="Width" Value="50" />
      <Setter Property="Height" Value="50" />
      <Setter Property="Margin" Value="20" />
      <Setter Property="HorizontalAlignment" Value="Left" />
      <Style.Triggers>
        <EventTrigger RoutedEvent="MouseEnter">
            <BeginStoryboard>
                <Storyboard>
                  <DoubleAnimation To="300" Duration="0:0:1.5"
                    AccelerationRatio="0.10" DecelerationRatio="0.25"
                    Storyboard.TargetProperty="(Canvas.Width)" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="MouseLeave">
            <BeginStoryboard>
                <Storyboard>
                  <DoubleAnimation Duration="0:0:1.5"
                    AccelerationRatio="0.10" DecelerationRatio="0.25"
                    Storyboard.TargetProperty="(Canvas.Width)" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
      </Style.Triggers>
    </Style>

    2.VisualStateManager

    <ControlTemplate TargetType="Button"
                     xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
      <Grid >
        <vsm:VisualStateManager.VisualStateGroups>
          <vsm:VisualStateGroup x:Name="CommonStates">

            <vsm:VisualStateGroup.Transitions>

              <!--Take one half second to trasition to the MouseOver state.-->
              <vsm:VisualTransition To="MouseOver"
                                  GeneratedDuration="0:0:0.5"/>
            </vsm:VisualStateGroup.Transitions>

            <vsm:VisualState x:Name="Normal" />

            <!--Change the SolidColorBrush, ButtonBrush, to red when the
                mouse is over the button.-->
            <vsm:VisualState x:Name="MouseOver">
              <Storyboard>
                <ColorAnimation Storyboard.TargetName="ButtonBrush"
                                Storyboard.TargetProperty="Color" To="Red" />
              </Storyboard>
            </vsm:VisualState>
          </vsm:VisualStateGroup>
        </vsm:VisualStateManager.VisualStateGroups>
        <Grid.Background>
          <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
        </Grid.Background>
      </Grid>
    </ControlTemplate>

  • 相关阅读:
    在 Windows 10 中创建任何大小的虚拟测试文件的 2 种方法
    最近的github又不稳了。。ip host 大法来
    windows mklink /d /h /j 精讲
    kafka-manager配置和使用
    Java——七种垃圾收集器+JDK11最新ZGC
    聚簇索引和非聚簇索引(通俗易懂 言简意赅)
    【转载】Java中的锁机制 synchronized & 偏向锁 & 轻量级锁 & 重量级锁 & 各自优缺点及场景 & AtomicReference
    都1202年了奉劝那些还在用centos6的gs,赶紧切ubuntu-Centos6 升级 gcc 惨痛教训
    Tamper Chrome – 请求修改扩展,可用于Web安全测试
    线程、线程池三大方法、七大参数、四种策略
  • 原文地址:https://www.cnblogs.com/yaksea/p/1631342.html
Copyright © 2011-2022 走看看