我添加了一个箭头来指示工具提示中的文本框。当文本框远离屏幕边缘时,这非常有效。但是当它靠近屏幕边缘时。工具提示位置发生变化,箭头显示在左侧。
Here is the Image
Correct as expected, since TextBox in away from edges.
但是当 TextBox 靠近边缘时。我看到这个
我想看到工具提示右侧第二张图片中的箭头。
这是代码
<Grid Grid.Column="0" Width="10"
Margin="1,0,-1,0"
Background="Transparent">
<Path Height="15" Stretch="Fill"
Fill="{DynamicResource ControlsValidationBrush}"
Data="F1 M 287.328,237.333L 319.344,255.818L 319.344,218.849L 287.328,237.333 Z " />
</Grid>
<Border Grid.Column="1"
Background="{DynamicResource ControlsValidationBrush}"
CornerRadius="0">
<TextBlock MaxWidth="250"
Margin="8,7,8,7"
Foreground="{DynamicResource WhiteBrush}"
Text="{Binding (Validation.Errors)[0].ErrorContent}"
TextWrapping="Wrap"
UseLayoutRounding="false" />
</Border>
我创建了Controltemplate
对于工具提示,并根据工具提示的位置显示/隐藏向右或向左箭头。这是它的 Xaml:
<ControlTemplate x:Key="tooltipTemplate" TargetType="{x:Type ToolTip}">
<StackPanel Orientation="Horizontal">
<Grid x:Name="LeftGrid"
Width="10"
Margin="1,0,-1,0"
Background="Transparent">
<Path Height="15" Stretch="Fill"
Fill="Red"
Data="F1 M 287.328,237.333L 319.344,255.818L 319.344,218.849L 287.328,237.333 Z " />
</Grid>
<Border
Background="Red"
CornerRadius="0">
<TextBlock MaxWidth="250"
Margin="8,7,8,7"
Foreground="{DynamicResource WhiteBrush}"
Text="This is tooltip"
TextWrapping="Wrap"
UseLayoutRounding="false" />
</Border>
<Grid x:Name="RightGrid" Width="10"
Margin="1,0,-1,0"
Background="Transparent">
<Path Height="15" Stretch="Fill"
Fill="Red"
Data="F1 M 287.328,237.333L 319.344,255.818L 319.344,218.849L 287.328,237.333 Z " />
</Grid>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="Placement" Value="Left">
<Setter TargetName="LeftGrid" Property="Visibility" Value="Hidden"/>
<Setter TargetName="RightGrid" Property="Visibility" Value="Visible"/>
</Trigger>
<Trigger Property="Placement" Value="Right">
<Setter TargetName="LeftGrid" Property="Visibility" Value="Visible"/>
<Setter TargetName="RightGrid" Property="Visibility" Value="Hidden"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ToolTip x:Key="myToolTip" Template="{StaticResource tooltipTemplate}">
Thanks
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)