1. 程式人生 > 實用技巧 >WPF Popup繫結目標控制元件上下左右位置

WPF Popup繫結目標控制元件上下左右位置

Popup的 PlacementTarget屬性為繫結某個控制元件Placement為上下左右方位,效果如下

TextBox

<TextBox x:Name="txt_Code" Grid.Column="1"
         Width="200"
         Height="28"
         FontSize="18"
         HorizontalAlignment="Left"
         Opacity="1"                             
         Margin="20,5,20,5"
         MaxLength
="7" input:InputMethod.IsInputMethodEnabled="False" VerticalContentAlignment="Center" > <TextBox.Resources> <Style TargetType="{x:Type Border}"> <Setter Property="
CornerRadius" Value="2"/> <Setter Property="BorderBrush" Value="#c1d0dc"/> </Style> </TextBox.Resources> </TextBox>

Popup

Popup x:Name="Popup_tick"                           
                               StaysOpen="False"                              
                               AllowsTransparency
="True" IsOpen="False" PlacementTarget="{Binding ElementName=txt_Code}" Placement="Right" > <Path Data="M 0,100 Q 35,140 54,190 Q 100,45 168,0 S 90,40 50,150 Q 40,136 0,100 Z " Fill="#89BF04" Stretch="Fill" Margin="2,0,0,0" VerticalAlignment="Bottom" HorizontalAlignment="Center" Height="28" Width="30" /> </Popup>