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>
查看全文
相关阅读:
Understanding about Baire Category Theorem
Isometric embedding of metric space
Convergence theorems for measurable functions
Mindmap for "Principles of boundary element methods"
Various formulations of Maxwell equations
Existence and uniqueness theorems for variational problems
Kernels and image sets for an operator and its dual
[loj6498]农民
[luogu3781]切树游戏
[atAGC051B]Three Coins
原文地址:https://www.cnblogs.com/tcjiaan/p/2422688.html
最新文章
关联规则挖掘相关资料
152. Maximum Product Subarray
221. Maximal Square
第四届CCF大数据学术会议征文通知
283. Move Zeroes
226. Invert Binary Tree
104. Maximum Depth of Binary Tree
我的gvim配置
Educational Codeforces Round 97 G. Death DBMS题解
AtCoder Regular Contest 106 D Powers 解题报告
热门文章
一道难题
AtCoder Regular Contest 105 C题解题报告
Atcoder HHKB Programming Contest 2020 ABCDE题
2020 ICPC North America Championship Problem G
Codeforces contest-1408 (Grakn Forces 2020)题解
最小生成树及最大生成树(算法及正确性简单证明)
从《挪威的森林》谈青年的成长
Notes for Mathematical Electromagnetism
$L_2(Omega)$ is a subspace of $H^{-1}(Omega)$
Baire Category Theorem
Copyright © 2011-2022 走看看