TipControl.xaml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <ContentControl x:Class="YSAI.Controls.tip.TipControl"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:local="clr-namespace:YSAI.Controls.tip">
  7. <ContentControl.Resources>
  8. <local:ToolTipOffsetConverter x:Key="ToolTipOffsetConverter" />
  9. <Style TargetType="local:TipControl">
  10. <Setter Property="ToolTipForeground" Value="{DynamicResource TitleForeground}" />
  11. <Setter Property="Background" Value="{DynamicResource CaptionActiveBackgroundBrush}" />
  12. <Setter Property="Template">
  13. <Setter.Value>
  14. <ControlTemplate TargetType="local:TipControl">
  15. <Grid>
  16. <Popup
  17. x:Name="PART_Popup"
  18. AllowsTransparency="True"
  19. IsHitTestVisible="false"
  20. Placement="Center"
  21. PlacementTarget="{Binding ElementName=PART_Content}">
  22. <Border Name="Border" Padding="0,10,0,0">
  23. <Grid>
  24. <Border
  25. x:Name="PART_Arrow"
  26. Width="30"
  27. Height="30"
  28. Background="{TemplateBinding Background}"
  29. CornerRadius="3"
  30. RenderTransformOrigin="0.5,0.5">
  31. <Border.RenderTransform>
  32. <TransformGroup>
  33. <ScaleTransform />
  34. <SkewTransform />
  35. <RotateTransform Angle="45" />
  36. <TranslateTransform />
  37. </TransformGroup>
  38. </Border.RenderTransform>
  39. </Border>
  40. <Border
  41. Width="{TemplateBinding Width}"
  42. Height="{TemplateBinding Height}"
  43. Background="{TemplateBinding Background}"
  44. BorderThickness="0"
  45. CornerRadius="3">
  46. <ContentPresenter
  47. Margin="10"
  48. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  49. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  50. ContentSource="ToolTipContent"
  51. TextBlock.Foreground="{TemplateBinding ToolTipForeground}" />
  52. </Border>
  53. </Grid>
  54. </Border>
  55. </Popup>
  56. <ContentPresenter x:Name="PART_Content" />
  57. </Grid>
  58. <ControlTemplate.Triggers>
  59. <Trigger Property="Placement" Value="Right">
  60. <Setter TargetName="PART_Popup" Property="VerticalOffset" Value="0" />
  61. <Setter TargetName="PART_Arrow" Property="HorizontalAlignment" Value="Left" />
  62. <Setter TargetName="Border" Property="Padding" Value="10,0,0,0" />
  63. <Setter TargetName="PART_Popup" Property="HorizontalOffset">
  64. <Setter.Value>
  65. <MultiBinding Converter="{StaticResource ToolTipOffsetConverter}">
  66. <Binding ElementName="PART_Content" Path="ActualWidth" />
  67. <Binding ElementName="Border" Path="ActualWidth" />
  68. </MultiBinding>
  69. </Setter.Value>
  70. </Setter>
  71. </Trigger>
  72. <Trigger Property="Placement" Value="Left">
  73. <Setter TargetName="PART_Popup" Property="VerticalOffset" Value="0" />
  74. <Setter TargetName="PART_Arrow" Property="HorizontalAlignment" Value="Right" />
  75. <Setter TargetName="Border" Property="Padding" Value="0,0,10,0" />
  76. <Setter TargetName="PART_Popup" Property="HorizontalOffset">
  77. <Setter.Value>
  78. <MultiBinding Converter="{StaticResource ToolTipOffsetConverter}" ConverterParameter="-">
  79. <Binding ElementName="PART_Content" Path="ActualWidth" />
  80. <Binding ElementName="Border" Path="ActualWidth" />
  81. </MultiBinding>
  82. </Setter.Value>
  83. </Setter>
  84. </Trigger>
  85. <Trigger Property="Placement" Value="Top">
  86. <Setter TargetName="PART_Popup" Property="HorizontalOffset" Value="0" />
  87. <Setter TargetName="PART_Arrow" Property="VerticalAlignment" Value="Bottom" />
  88. <Setter TargetName="Border" Property="Padding" Value="0,0,0,10" />
  89. <Setter TargetName="PART_Popup" Property="VerticalOffset">
  90. <Setter.Value>
  91. <MultiBinding Converter="{StaticResource ToolTipOffsetConverter}" ConverterParameter="-">
  92. <Binding ElementName="PART_Content" Path="ActualHeight" />
  93. <Binding ElementName="Border" Path="ActualHeight" />
  94. </MultiBinding>
  95. </Setter.Value>
  96. </Setter>
  97. </Trigger>
  98. <Trigger Property="Placement" Value="Bottom">
  99. <Setter TargetName="PART_Popup" Property="HorizontalOffset" Value="0" />
  100. <Setter TargetName="PART_Arrow" Property="VerticalAlignment" Value="Top" />
  101. <Setter TargetName="Border" Property="Padding" Value="0,10,0,0" />
  102. <Setter TargetName="PART_Popup" Property="VerticalOffset">
  103. <Setter.Value>
  104. <MultiBinding Converter="{StaticResource ToolTipOffsetConverter}">
  105. <Binding ElementName="PART_Content" Path="ActualHeight" />
  106. <Binding ElementName="Border" Path="ActualHeight" />
  107. </MultiBinding>
  108. </Setter.Value>
  109. </Setter>
  110. </Trigger>
  111. <Trigger Property="IsMouseOver" Value="True">
  112. <Setter TargetName="PART_Popup" Property="IsOpen" Value="true" />
  113. </Trigger>
  114. <Trigger Property="ToolTipContent" Value="{x:Null}">
  115. <Setter TargetName="PART_Popup" Property="IsOpen" Value="false" />
  116. </Trigger>
  117. </ControlTemplate.Triggers>
  118. </ControlTemplate>
  119. </Setter.Value>
  120. </Setter>
  121. </Style>
  122. </ContentControl.Resources>
  123. </ContentControl>