Tải bản đầy đủ - 0 (trang)
7-21. Display WPF Windows in a Windows Forms Application

7-21. Display WPF Windows in a Windows Forms Application

Tải bản đầy đủ - 0trang

CHAPTER 7 ■ WINDOWS FORMS



private CancelEventHandler modelessWindowCloseHandler;

public Recipe07_21()

{

// Initialization code is designer generated and contained

// in a separate file named Recipe07-21.Designer.cs.

InitializeComponent();

modelessWindowCloseHandler = new CancelEventHandler(Window_Closing);

}

// Handles the button click event to open and close the modeless

// WPF window.

private void OpenModeless_Click(object sender, EventArgs e)

{

if (modelessWindow == null)

{

modelessWindow = new Window1();

// Add an event handler to get notification when the window

// is closing.

modelessWindow.Closing += modelessWindowCloseHandler;

// Change the button text.

btnOpenModeless.Text = "Close Modeless Window";

// Show the Windows Form.

modelessWindow.Show();

}

else

{

modelessWindow.Close();

}

}

// Handles the button click event to open the modal WPF Window.

private void OpenModal_Click(object sender, EventArgs e)

{

// Create and display the modal window.

Window1 window = new Window1();

window.ShowDialog();

}

// Handles the WPF Window's Closing event for the modeless window.

private void Window_Closing(object sender, CancelEventArgs e)

{

// Remove the event handler reference.

modelessWindow.Closing -= modelessWindowCloseHandler;

modelessWindow = null;



361



www.it-ebooks.info



CHAPTER 7 ■ WINDOWS FORMS



// Change the button text.

btnOpenModeless.Text = "Open Modeless Window";

}

}

}

The following XAML provides the declaration of the WPF Window that is opened when the user clicks

either of the buttons on the Windows Forms application:


xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Recipe07_21" Height="200" Width="300">





Tài liệu bạn tìm kiếm đã sẵn sàng tải về

7-21. Display WPF Windows in a Windows Forms Application

Tải bản đầy đủ ngay(0 tr)

×