zoukankan
html css js c++ java
继续聊WPF——Expander控件(2)
上一篇文章简单说了一下Expander控件,本文将编写一个自义模板的Expander控件,如下图所示:
<Window x:Class="Expander_Sample2.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Window.Resources> <!-- ToogleButton的模板, 因为要进和状态切换,故要用到ToggleButton控件 --> <ControlTemplate x:Key="ToggleButtonTemp" TargetType="{x:Type ToggleButton}"> <Border x:Name="bd" BorderThickness="1" CornerRadius="1,1,1,1"> <Border.Background> <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> <GradientStop Color="LightGray" Offset="0"/> <GradientStop Color="White" Offset="1"/> </LinearGradientBrush> </Border.Background> <Border.BorderBrush> <LinearGradientBrush StartPoint="0,0" EndPoint="1,1"> <GradientStop Color="Black" Offset="0"/> <GradientStop Color="Gray" Offset="1"/> </LinearGradientBrush> </Border.BorderBrush> <Path Margin="2,2,2,2" Fill="Black" x:Name="p" Data="M 0,0 L 4,5 L8,0 Z" HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="bd" Property="Background"> <Setter.Value> <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> <GradientStop Color="LightGreen" Offset="0"/> <GradientStop Color="White" Offset="1"/> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="p" Property="Data" Value="M0,5 L8,5 L4,0 Z"/> </Trigger> <Trigger Property="IsEnabled" Value="True"> <Setter TargetName="bd" Property="BorderBrush" Value="Gray"/> <Setter TargetName="p" Property="Fill" Value="Gray"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <!-- Expnder的样式 --> <Style TargetType="{x:Type Expander}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Expander}"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="auto"/> <RowDefinition x:Name="gr" Height="0"/> </Grid.RowDefinitions> <BulletDecorator Background="DarkTurquoise" Grid.Row="0" VerticalAlignment="Center" > <BulletDecorator.Bullet> <ToggleButton Margin="1,1,1,1" Height="18" Width="18" Template="{StaticResource ToggleButtonTemp}" IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" OverridesDefaultStyle="True"/> </BulletDecorator.Bullet> <ContentPresenter HorizontalAlignment="Center" Margin="1,1,1,1" ContentSource="Header"/> </BulletDecorator> <Border x:Name="scv" Background="LightGray" BorderThickness="1" BorderBrush="Black" Grid.Row="1" > <ContentPresenter Margin="0" ContentSource="Content"/> </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsExpanded" Value="True"> <Setter TargetName="gr" Property="Height" Value="{Binding Path=DesiredSize/Height,ElementName=scv}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <Expander Margin="10,10" Height="210" Width="130" OverridesDefaultStyle="True"> <Expander.Header> <TextBlock Text="相见恨晚" FontWeight="Bold" FontSize="16"/> </Expander.Header> <TextBlock TextWrapping="Wrap"> 如果相见不会太晚,我们就不会悲伤,和你堂堂的手牵手,过得好简单, 若我有天不见了,或许你会比较快乐,虽然有万般舍不得,也不愿看你难割舍 若我有天不在了。请你原谅我的困扰,虽然你给我的不算少,只是我没福气要就算是完美。 </TextBlock> </Expander> </Grid> </Window>
查看全文
相关阅读:
POJ 1166 The Clocks 高斯消元 + exgcd(纯属瞎搞)
防止登录页面出如今frame中
android--显式跳转和隐式跳转的差别使用方法
卫星照片
poj 2586 Y2K Accounting Bug (贪心)
【转】关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
【转】在Eclipse中使用PyDev进行Python开发
【转】eclipse + Pydev 配置Python开发环境
【转】Python自动化测试 (一) Eclipse+Pydev 搭建开发环境
【转】Eclipse的启动问题【an error has occurred see the log file】
原文地址:https://www.cnblogs.com/javawebsoa/p/2457972.html
最新文章
UVA 11149
Channel Allocation (poj 1129 dfs)
(五岁以下儿童)NS3样本演示:桥模块演示样品csma-bridge.cc凝视程序
UVALive 5103 Computer Virus on Planet Pandora Description 一些新兴需求模式的字符串 AC自己主动机
CORS原理
Java 文件句柄泄露问题解决小记
[链接] Java语言规范里关于Java类与接口的卸载的描述
备忘录模式
一个Java8模型的batch队列
短信猫
热门文章
Java对ad操作
spring使用context:property-placeholder载不进属性问题 wangbiglei 发表于1年前 原 spring使用context:property-placeholder载不进属性问题
Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
spring扫描自定义注解并进行操作
[读书笔记]Java类载入过程
Leetcode 264(Ugly Number II)
设计模式—生产者消费者模式
解决Keystore was tampered with, or password was incorrect
ORACLE使用WITH AS和HINT MATERIALIZE优化SQL解决FILTER效率低下
AndroidStudio 中怎样查看获取MD5和SHA1值(应用签名)
Copyright © 2011-2022 走看看