加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用c#在wpf中定位弹出窗口

发布时间:2020-12-15 22:29:56 所属栏目:百科 来源:网络整理
导读:我已经在按钮鼠标悬停上放置了一个弹出窗口.每当我将鼠标悬停在该按钮上时,我的自定义设计弹出窗口就会完美显示.但是它并没有完美地指向按钮.怎么这样..? 现在我的弹出窗口看起来像 我希望箭头标记指向帮助按钮如何实现它.. 这是我在xaml中按钮和弹出窗口的
我已经在按钮鼠标悬停上放置了一个弹出窗口.每当我将鼠标悬停在该按钮上时,我的自定义设计弹出窗口就会完美显示.但是它并没有完美地指向按钮.怎么这样..?
现在我的弹出窗口看起来像

enter image description here

我希望箭头标记指向帮助按钮如何实现它..

这是我在xaml中按钮和弹出窗口的代码

<telerik:RadButton Name="btnH" Grid.Column="1" HorizontalAlignment="Left" Margin="444,56,0" Grid.Row="2" VerticalAlignment="Top" 
                 Width="23" Height="23" BorderThickness="6" BorderBrush="#4E4E4E">
            <Image Source="Images/help.png" />
            <telerik:RadButton.Triggers>
                    <EventTrigger RoutedEvent="MouseEnter">
                        <BeginStoryboard>
                        <Storyboard TargetName="TooltipPopup" TargetProperty="IsOpen">
                                <BooleanAnimationUsingKeyFrames  FillBehavior="HoldEnd">
                                    <DiscreteBooleanKeyFrame KeyTime="00:00:00"  Value="True" />
                                </BooleanAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>

??????????????
????????????
????????????????
????????????????????
????????????????????????
????????????????????
????????????????
????????????

以下是自定义usercontrol xaml,它在弹出窗口中调用

<UserControl
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="WPFTest.UCToolTip" 
         mc:Ignorable="d" Height="231.493" Width="362.075"
         Background="Transparent"  >
<UserControl.Resources>
    <Style TargetType="{x:Type Hyperlink}">
                 <Setter Property="TextBlock.TextDecorations" Value="{x:Null}" />
    </Style>
</UserControl.Resources>
<Grid Margin="10,0">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid Background="red" Margin="0,182,133">            

    </Grid>
    <Polygon
    Points="0.5,0 15,30" Stroke="Orange" Fill="Orange" Margin="0,98,101" />
</Grid>

解决方法

将此样式用于弹出窗口:

<Style TargetType="Popup">
                <Style.Triggers>
                    <Trigger Property="IsOpen" Value="true">
                        <Setter Property="PlacementTarget" Value="{Binding ElementName=btnH }" />
                        <Setter Property="Placement" Value="Top" />
                        <Setter Property="VerticalOffset" Value="-5" />
                        <Setter Property="HorizontalOffset" Value="5" />
                    </Trigger>
                </Style.Triggers>
            </Style>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读