Moving from a WPF user control to a window?

I am working on a command line application and recently decided to add a wpf window to the application. I added this as a UserControl, however I noticed that I could not name this class using ShowDialog () from my main code;

I tried changing the base class from UserControl to Window, however an error occurs:

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

Error 1 Partial declarations "ExcelExample.UserControl1" should not indicate another classesExcelExample base

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

+4
source share
1 answer

To change the base class, it is not enough to change it only in the code. You must also change the root tag and any nested elements in the 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 should 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> 
+9
source

Source: https://habr.com/ru/post/1308893/


All Articles