• wpf 资源的重用


    资源的利用

    1) Window.Resource

    <Window.Resource>

    <ImageBrush x:Key="TitleBrush" TileMode="Tile" Opacity="0.3" ImageSource="happyface.jpg" >

    </ImageBrush>

    </Window.Resource>

    引用

    <Button Background="{ StaticResource TileBrush}" >

    2) style

    <Style x:Key="BigFontButtonStyle">

    <Style.Setters>

    <Setter Property="Control.FontFamily" Value=" Times Nem Roman" />

    <Setter Event="Control.MouseLeave" Handler="element_MouseLeave" />

    </Style.Setters>

    <Style.Triggers>

    //属性值发生变化
    <Trigger Property="Control.IsFocused" Value="True" >

    <Setter Property="Control.Foreground" Value="Darked" />

    </Trigger>


    <MultiTrigger>

    <MultiTrigger.Conditions>

    <Conditon Property="Control.IsFocued" value="True">
    <Conditon Property="Control,IsMouseOver" value="True">

    </MultiTrigger.Conditions>

    <MultiTrigger.Setters>

    <Setter Property="Control.Foreground" Value="Darked">

    </MultiTrigger.Setters>

    </MultiTrigger>


    //事件发生变化

    <Style.Triggers>

    <EventTrigger RouteEvent="Mouse.MouseEnter" >

    <EventTrigger.Actions>


    <BeginStoryboard>

    <Storyboard>

    <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="FontSize"
    To="22" />

    </Storyboard>

    </BeginStoryboard>

    <EventTrigger.Actions>

    </EventTrigger>

    </Style.Triggers>

    </Style.Triggers>

    </Style>

    3)数据模板和控件模板

    其一
    <ListBox x:Name="ListBox_PeopleList" ItemTemplate="{StaticResource MyTemplate}" />

    <Window.Resources>
    <!--列表模板-->
    <DataTemplate x:Key="MyTemplate" DataType="{x:Type demo:People}">
    <Grid VerticalAlignment="Center" HorizontalAlignment="Center"
    Margin="4,4,4,4" >
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto"/>
    <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <Image Source="{Binding Photo}" Width="50" Height="50"
    Grid.Column="0" Grid.RowSpan="1"/>
    <TextBlock Text="{Binding Name}" Grid.Column="1"
    Grid.ColumnSpan="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </Grid>
    </DataTemplate>
    </Window.Resources>

    其二
    <DataTemplate x:Key="hightlightTmp">
    <Grid>
    <Grid.RowDefinitions>
    <RowDefinition Height="auto"/>
    <RowDefinition Height="auto"/>
    </Grid.RowDefinitions>
    <StackPanel Margin="0,5,0,0" Grid.Row="0" Orientation="Horizontal">
    <TextBlock Margin="2,0" FontWeight="Bold" FontSize="14">
    <TextBlock.Text>
    <Binding Path="Name"
    StringFormat="姓名:{0}"/>
    </TextBlock.Text>
    </TextBlock>
    <TextBlock Margin="20,0">
    <TextBlock.Text>
    <Binding Path="Age"
    StringFormat="年龄:{0}"/>
    </TextBlock.Text>
    </TextBlock>
    </StackPanel>
    <TextBlock Margin="0,2,0,5" Grid.Row="1">
    <TextBlock.Text>
    <Binding Path="Email"
    StringFormat="电邮:{0}"/>
    </TextBlock.Text>
    </TextBlock>
    </Grid>
    </DataTemplate>

    <Style x:Key="cmbStyle" TargetType="{x:Type ComboBoxItem}">
    <Style.Triggers>
    <Trigger Property="IsHighlighted" Value="True">
    <Setter Property="ContentTemplate"
    Value="{StaticResource hightlightTmp}"/>
    </Trigger>
    </Style.Triggers>
    </Style>

    控件模板

    <Button Content="看看我的变化" Height="59" HorizontalAlignment="Left" Margin="99,88,0,0" Name="button1"
    VerticalAlignment="Top" Width="94" Background="#FFB4AEFC">
    <Button.Template>
    <ControlTemplate>
    <!--定义视觉树-->
    <Grid>
    <Ellipse Height="{TemplateBinding Control.Height}"
    Fill="{TemplateBinding Button.Background}"
    Width="{TemplateBinding Button.Width}" />
    <TextBlock Name="txtBlock" Margin="{TemplateBinding Button.Padding}"
    VerticalAlignment="Center"
    HorizontalAlignment="Center"
    Text="{TemplateBinding Button.Content}"
    />
    </Grid>
    <!--定义视觉树结束-->
    <!--定义触发器-->
    <ControlTemplate.Triggers>
    <Trigger Property="Button.IsMouseOver" Value="True">
    <Setter Property="Button.Foreground" Value="Red"/>
    </Trigger>
    </ControlTemplate.Triggers>
    <!--定义触发器结束-->
    </ControlTemplate>
    </Button.Template>
    </Button>

  • 相关阅读:
    Oracle:windows下,纯控制台方式(即前台,而不是后台服务)启动oracle实例、及tnslsnr实例
    创建本地离线 .deb包 仓库:ubuntu、debian、mint等:dpkgdev工具包中的“dpkgscanpackages”
    ubuntu22.04liveserveramd64.iso:安装界面的高级应用
    Golang 实现 Redis(11): RDB 文件格式 Finley
    Golang 实现 Redis(10): 本地原子性事务 Finley
    threadX
    嵌入式调试
    网络定位
    linux驱动移植usb驱动基础
    linux驱动移植LCD触摸屏驱动案例
  • 原文地址:https://www.cnblogs.com/wwwfj/p/3635201.html
Copyright © 2020-2023  润新知