2016-04-22 73 views
4

我已經在按鈕mouseover上放置了一個彈出窗口。每次當我將鼠標放在該按鈕上時,我的自定義設計彈出窗口正在顯示完美.Butit沒有完美地指出按鈕。如何做... ..? 現在我的彈出式看起來像使用c彈出窗口定位在wpf#

enter image description here

我想要那個箭頭指向的是幫助按鈕如何acheive吧..

這裏是我在XAML

按鈕,彈出代碼
<telerik:RadButton Name="btnH" Grid.Column="1" HorizontalAlignment="Left" Margin="444,56,0,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> 

以下是自定義用戶控件的XAML這AMN調用彈出

<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,0,0"> 
    <Grid.RowDefinitions> 
     <RowDefinition/> 
     <RowDefinition Height="Auto"/> 
    </Grid.RowDefinitions> 
    <Grid Background="red" Margin="0,0,182,133">    

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

+0

哎,做了回答helped..or你仍然得到了一些問題? –

回答

1

使用本風格爲您的Popup

<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> 
0

我認爲Kylo指出了你的正確答案。如果你在用戶控件中刪除邊距,它應該可以工作。

這是usercontrol的代碼。

<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="130" Width="180" 
     Background="Transparent" > 
    <UserControl.Resources> 
     <Style TargetType="{x:Type Hyperlink}"> 
      <Setter Property="TextBlock.TextDecorations" Value="{x:Null}" /> 
     </Style> 
    </UserControl.Resources> 
    <Grid Margin="10,0,0,0"> 
     <Grid.RowDefinitions> 
      <RowDefinition/> 
      <RowDefinition Height="Auto"/> 
     </Grid.RowDefinitions> 
     <Grid Background="red" Margin="0,0,0,32"> 

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

並且窗口的代碼。

<Window x:Class="WpfTest.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
     xmlns:uc="clr-namespace:WpfTest" 
     Title="MainWindow" Height="350" Width="525"> 
    <Window.Resources> 
     <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="0" /> 
        <Setter Property="HorizontalOffset" Value="145" /> 
       </Trigger> 
      </Style.Triggers> 
     </Style>   
    </Window.Resources>  
    <Grid> 
     <telerik:RadButton Name="btnH" Grid.Column="1" HorizontalAlignment="Left" Margin="300,175,0,0" Grid.Row="2" VerticalAlignment="Top" 
       Width="50" 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> 

       <EventTrigger RoutedEvent="MouseLeave"> 
        <BeginStoryboard> 
         <Storyboard TargetName="TooltipPopup" TargetProperty="IsOpen"> 
          <BooleanAnimationUsingKeyFrames FillBehavior="HoldEnd"> 
           <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False" /> 
          </BooleanAnimationUsingKeyFrames> 
         </Storyboard> 
        </BeginStoryboard> 
       </EventTrigger> 
      </telerik:RadButton.Triggers> 

     </telerik:RadButton> 

     <Popup x:Name="TooltipPopup" AllowsTransparency="True"> 
      <StackPanel> 
       <uc:UCToolTip></uc:UCToolTip> 
      </StackPanel> 
     </Popup> 

    </Grid> 
</Window> 
0

Here是一個小型圖書館氣球的WPF,我覺得你想要做什麼。

用法:

<geometry:Balloon ConnectorAngle="25" 
        CornerRadius="15" 
        PlacementOptions="Bottom, Center" 
        PlacementTarget="{Binding ElementName=Target}"> 
    <!-- content here --> 
</geometry:Balloon>