In my project, I have a class MainViewModel
where I have DataContext
property and I load MENU in MainWindow
from Database using DataContext
. In MainWindow
, I have a ContentControl to load UserControl. When I click MENU ITEMS, it should calls a function of MainViewModel
to load UserControl in the ContentControl. and here I am stuck in a loop.
MainWindow:
public partial class MainWindow : Window
{
public MainWindow()
{
DataContext = new MainViewModel();
}
}
XAML:
<ContentControl x:Name="contentCont1" />
MainViewModel:
public class MainViewModel: ViewModelBase
{
UCSale ucSale = new UCSale();
MainWindow mw = new MainWindow(); //IS IT ALLOED ?
public MainWindow()
{
Window1.contentCont1.Children.Add(ucSale );;
}
private void FillMenuItems()
{
//LOAD MENU ITEMS FROM DATABASE
}
}