1 <Style BasedOn="{StaticResource {x:Type ToolTip}}" TargetType="ToolTip"> 2 <Setter Property="Template"> 3 <Setter.Value> 4 <ControlTemplate TargetType="{x:Type ToolTip}"> 5 <Border Width="128" 6 Height="98" 7 BorderBrush="#FFDEE7F6" 8 BorderThickness="1" 9 CornerRadius="5"> 10 <Border.Background> 11 <SolidColorBrush Opacity="0.8" Color="White" /> 12 </Border.Background> 13 <Grid Margin="10,15,0,15"> 14 <Grid.RowDefinitions> 15 <RowDefinition /> 16 <RowDefinition /> 17 <RowDefinition /> 18 </Grid.RowDefinitions> 19 <TextBlock VerticalAlignment="Center" Text="{Binding Tag.CityName}" /> 20 <TextBlock Grid.Row="1" 21 VerticalAlignment="Center" 22 Text="{Binding Tag.Total, StringFormat=总量:{0} 辆}" /> 23 <TextBlock Grid.Row="2" 24 VerticalAlignment="Center" 25 Text="{Binding Tag.TodayCount, StringFormat=今日:{0} 辆}" /> 26 </Grid> 27 </Border> 28 </ControlTemplate> 29 </Setter.Value> 30 </Setter> 31 </Style>
<Path Name="HaiNan" Stroke="#FF113FBB" StrokeThickness="0.5" Tag="xxxxx"> <Path.ToolTip> <ToolTip DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}" /> </Path.ToolTip> </Path >
把需要传入tooltip内的值付到对象的tag对象内,然后tooltip绑定tag作为数据上下文