I haven't found this anywhere. Currently I'm making a WPF app and I ran into a problem. I need one page but data should be different depending on which button summoned the page. It would be kind of easy if not trying to stick with MVVM. I already have a button that passes needed data to the page cs file but I have no idea how to pass that data to the ViewModel.
DetailedViewPage.xaml.cs:
namespace unnamed
{
public partial class DetailedViewPage : BasePage<DetailedViewViewModel>
{
public DetailedViewPage(string position)
{
InitializeComponent();
}
}
//I'm using similar method to create new View
private void CreateNewWindow()
{
var MainWindow = (MainWindow) Application.Current.MainWindow;
var MWViewModel = (WindowViewModel) MainWindow.DataContext;
MWViewModel.CurrentPage = new DetailedViewPage("top");
}
}
BasePage.cs:
public class BasePage<VM> : Page
where VM : BaseViewModel, new()
{
private VM mViewModel;
public VM ViewModel
{
get { return ViewModel; }
set
{
if (mViewModel == value)
return;
mViewModel = value;
this.DataContext = mViewModel;
}
}
public BasePage()
{
this.Resources = ((MainWindow)Application.Current.MainWindow).Resources;
this.ViewModel = new VM();
}
}
DetailedViewViewModel.cs:
namespace unnamed
{
public class DetailedViewViewModel : BaseViewModel
{
public string PossitionShown { get; set; }
public DetailedViewViewModel()
{
}
}
}
So my goal here is to get that position variable from the page cs file to the ViewModel and assign to PossitionShown
.