amit srivastava
amit srivastava

Reputation: 743

How to have two XAML files with only one code behind file in WPF

I want to have two XAML file (Window) having a single code behind file(filename.xaml.cs) in my WPF application.

Upvotes: 3

Views: 1746

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564403

A code behind file corresponds to a single root element in XAML, so its not possible to have 2 files share a single code behind file.

That being said, you can often accomplish the underlying goals via other techniques, including:

  1. Use a UserControl for "child" content, and include the control directly in the main XAML file.
  2. Use merged resource dictionaries to separate out resources/styles

Upvotes: 1

Related Questions