Created UserControl and trying to load it on the main window. In the main window there is a StackPanel and a Grid, but wherever I try to add UC - the same error -

Argument 1: cannot convert from 'Performance.CPUUserControl' to 'System.Windows.UIElement'

Here is the code -

private void Window_Loaded(object sender, RoutedEventArgs e) { CPUUserControl cPUUser = new CPUUserControl(); UserControlGrid.Children.Add(cPUUser); StackPanelUserControl.Children.Add(cPUUser); //MainFrame.Navigate(cPUUser); } 

How to add UC to the window?

  • WPF is MVVM with bindings, xaml markup, etc. That is, in other words, .Children.Add is not appropriate in WPF, you need to forget this and leave it in WinForms! - EvgeniyZ
  • one
    What is your UserControl that it does not inherit a UIElement? Show class ad title - Andrew NOP
  • @AndreyNOP just right added UC. Right click on the project -> add -> User Contro. By the way there is no xaml designer in it. Filled on Git the project , can so will be more clear. - homeme
  • You have added the wrong UserControl, UserControl from WinForms has been added instead of WPF. It is necessary when selecting the Add New Item window in the left tree to select the WPF branch. - Andrey NOP
  • @ AndreiNOP thanks. Sorry ... There is no Chart element in this UC, which I really need. It turns out in WPF there are no Charts? You, by chance, do not know how to draw graphics in wpf? - homeme

0