■ WindowsFormsHost 엘리먼트에서 Visibility 속성을 설정하여 Windows Forms 컨트롤을 보이지 않게 만들거나 축소할 수 있다. 컨트롤이 보이지 않으면 표시되지 않지만 레이아웃 공간을 차지한다. 컨트롤이 축소되면 표시되지 않으며 레이아웃 공간을 차지하지도 않는다.
▶ 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 32 33 34 35 36 37 38 39 40 41 42 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:winform="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Width="800" Height="600" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Grid Margin="10" ShowGridLines="true"> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> <RowDefinition /> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <StackPanel Grid.Row="1" Grid.Column="1"> <Button Name="invisibleButton" Background="OrangeRed" Content="Click to make invisible" /> <WindowsFormsHost Name="host" Background="Yellow"> <winform:Button FlatStyle="Flat" Text="Windows Forms control" /> </WindowsFormsHost> <Button Name="collapseButton" Background="OrangeRed" Content="Click to collapse" /> </StackPanel> </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 55 56 57 58 59 60 61 |
using System; using System.Windows; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.invisibleButton.Click += invisibleButton_Click; this.collapseButton.Click += collapseButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region Click to make invisible 버튼 클릭시 처리하기 - invisibleButton_Click(sender, e) /// <summary> /// Click to make invisible 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void invisibleButton_Click(object sender, EventArgs e) { this.host.Visibility = Visibility.Hidden; } #endregion #region Click to collapse 버튼 클릭시 처리하기 - collapseButton_Click(sender, e) /// <summary> /// Click to collapse 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void collapseButton_Click(object sender, EventArgs e) { this.host.Visibility = Visibility.Collapsed; } #endregion } } |