Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing from WPF User Control to Window?

Tags:

c#

.net

wpf

I've been working on a commandline application, and have recently decided to add a wpf window to the application. I added this as a UserControl, however I noticed I can't call this class using ShowDialog() from my main code;

I've tried changing the Base class from a UserControl to Window, however an error occurs;

public partial class UserControl1 : Window
    {
        public UserControl1()
        {
            InitializeComponent();
        }

Error 1 Partial declarations of 'ExcelExample.UserControl1' must not specify different base classesExcelExample

I've added all the references found in my other WPF application to no avail. Help!

like image 631
wonea Avatar asked May 05 '10 14:05

wonea


1 Answers

In order to change the base class it is not sufficient to change it in code only. You must also change the root tag and any nested elements in accompanying XAML file. For example, you have something like:

<UserControl x:Class="Your.Namespace.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     <UserControl.Resources>
     </UserControl.Resources>
</UserControl>

You must change it to something like:

<Window x:Class="Your.Namespace.UserControl1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     <Window.Resources>
     </Window.Resources>
</Window>
like image 199
wpfwannabe Avatar answered Nov 10 '22 09:11

wpfwannabe