8,834
社区成员
发帖
与我相关
我的任务
分享
<UserControl x:Class="WpfTest.Controls.ExpandablePanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfTest.Controls"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
Loaded="ExpandablePanel_OnLoaded">
<UserControl.Resources>
<Style x:Key="PathStyle" TargetType="Path">
<Setter Property="Width" Value="20"/>
<Setter Property="Height" Value="20"/>
<Setter Property="Stroke" Value="Red"/>
<Setter Property="StrokeThickness" Value="1"/>
<Setter Property="Data" Value="M 5,10 10,5 15,10 M 5,15 10,10 15,15"/>
</Style>
<Style x:Key="ToggleButtonStyle" TargetType="ToggleButton">
<Setter Property="IsThreeState" Value="False"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border x:Name="Bd" Margin="{TemplateBinding Padding}" BorderThickness="1" BorderBrush="Transparent">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Path Grid.Column="0" x:Name="Arrow" Style="{StaticResource PathStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" SnapsToDevicePixels="False"/>
<ContentPresenter Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" RecognizesAccessKey="True" SnapsToDevicePixels="True"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="False">
<Setter TargetName="Arrow" Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="180"/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Arrow" Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="180"/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Bd" Property="Background" Value="AntiqueWhite"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Border Name="Main">
<Grid Margin="0">
<Grid.RowDefinitions>
<RowDefinition x:Name="Row0" Height="26"/>
<RowDefinition x:Name="Row1" Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="Col0" Width="*"/>
<ColumnDefinition x:Name="Col1" Width="26"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Name="HeaderBlock" Text="abcd" FontFamily="微软雅黑" FontSize="11" Foreground="#333" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<ToggleButton Grid.Row="0" Grid.Column="1" Name="ArrowButton" Style="{StaticResource ToggleButtonStyle}" Click="ArrowButton_OnClick"/>
<AdornerDecorator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Name="Ad">
<ContentPresenter Name="Content" Margin="0" Content="{Binding Content}"/>
</AdornerDecorator>
</Grid>
</Border>
</UserControl>
<controls:ExpandablePanel PanelHeader="aaa" Margin="5" BorderThickness="1" BorderBrush="Black">
<Border BorderThickness="1" BorderBrush="Red" Margin="5"></Border>
</controls:ExpandablePanel>