ToolTip
本例中有三个控件,两个TextBox和一个Ellipse。第一个TextBox中的ToolTipService.InitialShowDelay属性是ToolTip延迟显示的时间,ToolTipService.ShowDuration属性是ToolTip显示的时间,ToolTipService.BetweenShowDelay属性是当鼠标从一个控件移动到另一个控件上时的时间如果少于它的值,第二个控件的ToolTip就会立刻显示,如果大于这个值,就会按照第二个控件ToolTipService.InitialShowDelay的值来延迟显示。
XAML代码:
<Grid x:Name="LayoutRoot">
<TextBox HorizontalAlignment="Left" ToolTipService.InitialShowDelay="1000" ToolTipService.ShowDuration="5000" ToolTipService.BetweenShowDelay="2000" ToolTip="Useful information goes here." VerticalAlignment="Top" Height="125" Text="ToolTip with delay" Width="107.673"/>
<TextBox HorizontalAlignment="Left" Margin="111.673,0,0,0" VerticalAlignment="Top" Width="171.687" Height="125" Text="ToolTip with non-text content">
<TextBox.ToolTip>
<ToolTip>
<DockPanel Width="50" Height="40">
<Image Source="data\flower.jpg"/>
<TextBlock>Useful information goes here.</TextBlock>
</DockPanel>
</ToolTip>
</TextBox.ToolTip>
</TextBox>
<Ellipse Width="75"
Fill="Gray"
HorizontalAlignment="Left"
ToolTipService.InitialShowDelay="1000"
ToolTipService.ShowDuration="7000"
ToolTipService.BetweenShowDelay="2000" Margin="0,143.5,0,0" VerticalAlignment="Top" Height="77">
<Ellipse.ToolTip>
<ToolTip Placement="Right"
PlacementRectangle="50,0,0,0"
HorizontalOffset="10"
VerticalOffset="20"
HasDropShadow="false"
Opened="whenToolTipOpens"
Closed="whenToolTipCloses" >
<BulletDecorator>
<BulletDecorator.Bullet>
<Ellipse Height="10" Width="10" Fill="Red"/>
</BulletDecorator.Bullet>
<TextBlock>Uses the ToolTip Class</TextBlock>
</BulletDecorator>
</ToolTip>
</Ellipse.ToolTip>
</Ellipse>
</Grid>
在CS代码中,首先声明一个Ellipse,然后判断sender的类型是否是一个Ellipse,如果是,就把这个Ellipse的填充色变为Blue。如果sender为一个ToolTip,首先声明一个ToolTip,然后把sender赋值于它,然后得到父控件,然后再得到布局控件,并把它转化成Ellipse,并把Ellipse的填充色变为Blue。
whenToolTipCloses则是相反的过程。
CS代码:
void whenToolTipOpens(object sender, RoutedEventArgs e)
{
Ellipse ell = new Ellipse();
if (sender.GetType().FullName.Equals("System.Windows.Shapes.Ellipse"))
{
ell = (Ellipse)sender;
ell.Fill = Brushes.Blue;
}
else if (sender.GetType().FullName.Equals(
"System.Windows.Controls.ToolTip"))
{
ToolTip t = (ToolTip)sender;
Popup p = (Popup)t.Parent;
ell = (Ellipse)p.PlacementTarget;
ell.Fill = Brushes.Blue;
}
}
void whenToolTipCloses(object sender, RoutedEventArgs e)
{
Ellipse ell = new Ellipse();
if (sender.GetType().FullName.Equals(
"System.Windows.Shapes.Ellipse"))
{
ell = (Ellipse)sender;
ell.Fill = Brushes.Gray;
}
else if (sender.GetType().FullName.Equals(
"System.Windows.Controls.ToolTip"))
{
ToolTip t = (ToolTip)sender;
Popup p = (Popup)t.Parent;
ell = (Ellipse)p.PlacementTarget;
ell.Fill = Brushes.Gray;
}
}
《asp.net core精要讲解》 https://ke.qq.com/course/265696
《asp.net core 3.0》 https://ke.qq.com/course/437517
《asp.net core项目实战》 https://ke.qq.com/course/291868
《基于.net core微服务》 https://ke.qq.com/course/299524