■ Popup 엘리먼트의 Placement/CustomPopupPlacementCallback 속성을 사용해 커스텀 팝업 위치를 설정하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Grid> <ToggleButton Name="button" HorizontalAlignment="Center" VerticalAlignment="Center" Width="120" Height="30" Content="Show popup" /> <Popup Name="popup" PlacementTarget ="{Binding ElementName=button}" Placement="Custom" IsOpen="{Binding ElementName=button, Path=IsChecked}"> <TextBlock Width="200" Height="60" Background="LightGray" TextWrapping="Wrap"> Popup positioned by using CustomPopupPlacement callback delegate </TextBlock> </Popup> </Grid> </Window> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
using System.Windows; using System.Windows.Controls.Primitives; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(SetPopupLocation); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 팝업 위치 설정하기 - SetPopupLocation(popupSize, targetSize, offset) /// <summary> /// 팝업 위치 설정하기 /// </summary> /// <param name="popupSize">팝업 크기</param> /// <param name="targetSize">타겟 크기</param> /// <param name="offset">오프셋</param> /// <returns>커스텀 팝업 배치 배열</returns> private CustomPopupPlacement[] SetPopupLocation(Size popupSize, Size targetSize, Point offset) { CustomPopupPlacement placement1 = new CustomPopupPlacement(new Point(-50, 100), PopupPrimaryAxis.Vertical ); CustomPopupPlacement placement2 = new CustomPopupPlacement(new Point( 10, 20 ), PopupPrimaryAxis.Horizontal); CustomPopupPlacement[] placementArray = new CustomPopupPlacement[] { placement1, placement2 }; return placementArray; } #endregion } } |