DescriptionControl.xaml 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <UserControl x:Class="WpfDemo.DescriptionControl" Style="{DynamicResource Style1}"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:local="clr-namespace:WpfDemo">
  5. <UserControl.Resources>
  6. <Style x:Key="Style1" TargetType="UserControl">
  7. <Setter Property="Template">
  8. <Setter.Value>
  9. <ControlTemplate TargetType="local:DescriptionControl">
  10. <StackPanel MaxWidth="600">
  11. <ToggleButton x:Name="button" IsChecked="True" Width="90" Height="22" HorizontalAlignment="Right" Background="White" BorderBrush="LightGray">
  12. <StackPanel Orientation="Horizontal">
  13. <Path Data="M0,0.5 L7,0.5 M0,2.5 L7,2.5 M0,4.5 L7,4.5" Stroke="Black" VerticalAlignment="Center"/>
  14. <TextBlock Text="{TemplateBinding Header}" Margin="6,0,0,0"/>
  15. </StackPanel>
  16. </ToggleButton>
  17. <Grid x:Name="callout" Visibility="Collapsed" Margin="0,0,-3,0">
  18. <Path Data="M0,16 L16,0 L32,16 Z" Width="32" Height="12" Fill="WhiteSmoke" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,20,0" Panel.ZIndex="1"/>
  19. <Path Data="M0,16 L16,0 L32,16" Width="32" Height="12" Stroke="LightGray" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,20,0" Panel.ZIndex="2"/>
  20. <Border Background="WhiteSmoke" BorderThickness="1" BorderBrush="LightGray" Margin="0,11,0,0">
  21. <Border.Effect>
  22. <DropShadowEffect Color="LightGray" ShadowDepth="1" Direction="270" />
  23. </Border.Effect>
  24. <StackPanel>
  25. <TextBlock Text="{TemplateBinding Description}" Padding="10" TextWrapping="Wrap"/>
  26. <TextBlock x:Name="hyperlink" Padding="10">
  27. <Hyperlink Click="Hyperlink_Click">
  28. <TextBlock Text="{TemplateBinding LinkText}"/>
  29. </Hyperlink>
  30. </TextBlock>
  31. </StackPanel>
  32. </Border>
  33. </Grid>
  34. </StackPanel>
  35. <ControlTemplate.Triggers>
  36. <Trigger SourceName="button" Property="IsChecked" Value="True">
  37. <Setter TargetName="callout" Property="Visibility" Value="Visible"/>
  38. <Trigger.EnterActions>
  39. <BeginStoryboard>
  40. <Storyboard>
  41. <DoubleAnimation From="0" To="1" Duration="0:0:0.3" Storyboard.TargetName="callout" Storyboard.TargetProperty="Opacity"/>
  42. </Storyboard>
  43. </BeginStoryboard>
  44. </Trigger.EnterActions>
  45. </Trigger>
  46. <Trigger Property="Description" Value="">
  47. <Setter TargetName="callout" Property="Visibility" Value="Collapsed"/>
  48. </Trigger>
  49. <Trigger Property="Link" Value="">
  50. <Setter TargetName="hyperlink" Property="Visibility" Value="Collapsed"/>
  51. </Trigger>
  52. </ControlTemplate.Triggers>
  53. </ControlTemplate>
  54. </Setter.Value>
  55. </Setter>
  56. </Style>
  57. </UserControl.Resources>
  58. </UserControl>